0

I am trying to plot some extremely small values with matplotlib in jupiter 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. Here's my code:

%matplotlib inline
import matplotlib.pyplot as plt

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

ax.plot([0.2, 0.5, 0.8], [4E-300, 5E-300, 4E-300], marker='.')

And here's an example of what I am after with regard to y-axis values and notation:

enter image description here

Even with the following code:

%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='.')

I get the following plot:

enter image description here

spyrostheodoridis
  • 508
  • 2
  • 8
  • 27
  • I agree with both of your observations. I get the plot in the answer by Andrew Walker in version 1.2.0 but I get the plot in the question by spyrostheodoridis using version 1.5.1 of matplotlib – Shachit Iyer Sep 03 '17 at 22:27

1 Answers1

-1

Matplotlib (unlike, say Mathematica) expects you to supply the x- and y- values for all the points of interest in the plot. You could alter you code to evenly evaluate some function (say a gaussian) at even spacing in the unit interval

%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='.')

Which gives:

plot

Andrew Walker
  • 40,984
  • 8
  • 62
  • 84