Plot very small values with matplotlib in jupyter

jupyter, matplotlib, python

Solution

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}]')

Problem

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: And here's what I'm after:

Original source

Related problems