Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot very small values with matplotlib in jupyter

I am trying to plot some extremely small values with matplotlib in jupyter notebook (on a macbook pro). However, regardless if I set the y-axis limits, all I get is a flat line. What I am after is something like the example (png) below with regard to y-axis notation. I also tried the same example outside of jupyter and I still get the same results. Here's the code suggested by Andrew Walker on my previous question:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(13,6))
ax = fig.add_subplot(111)
plt.hold(True)


xs = np.linspace(0, 1, 101)
ys = 1e-300 * np.exp(-(xs-0.5)**2/0.01)

ax.plot(xs, ys, marker='.')

Here's what I get:

enter image description here

And here's what I'm after:

enter image description here

like image 688
spyrostheodoridis Avatar asked Oct 20 '25 02:10

spyrostheodoridis


1 Answers

The easiest thing to do is to just plot your values multiplied by 10^300, and then change the y-axis label:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(13,6))
ax = fig.add_subplot(111)
plt.hold(True)

xs = np.linspace(0, 1, 101)
ys = np.exp(-(xs-0.5)**2/0.01)

ax.plot(xs, ys, marker='.')

ax.set_ylabel(r'Value [x 10^{-300}]')
like image 164
Liam Coatman Avatar answered Oct 21 '25 16:10

Liam Coatman