1

I am trying to plot this simple list called energy_list which looks like

energy_list = [-31.996423234368955, -32.00000000000772, -32.000000000000014, -31.99500000000001,
               -31.999999999999982, -32.0, -32.000000000000014, -32.00000000000001,
               -32.00000000000002, -32.00000000000001, -32.0, -31.99500000000002,
               -32.000000000000014, -32.0, -32.000000000000036, -32.00000000000001, -32.0,
               -32.00000000000001, -32.000000000023576, -32.000000000000014, -32.00000000000007,
               -31.999999999999996, -32.0, -32.00000000000002, -32.0, -31.999999999999993,
               -32.00000000000001, -32.000000000000014, -31.995000000000005, -32.000000000429914,
               -32.0, -32.0, -31.99999999999999, -31.999999999999996, -31.99999999999999, -32.0,
               -31.999999999999996, -32.0, -32.00000000000001, -32.00000000000007,
               -32.00000000000001, -31.999999999999996, -32.000000000000014, -31.995000000000005,
               -32.00000000000001, -32.000000000000014, -32.00000000000001, -32.00000000000001,
               -32.000000000000014, -32.00000000000565]

The plot should be a somewhat constant function. But when I plot it using plt.plot(energy_list) I get this annoying plot:

enter image description here

What on earth is happening?

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • Does this answer your question? [Prevent scientific notation](https://stackoverflow.com/questions/28371674/prevent-scientific-notation) – Ignatius Reilly Mar 13 '23 at 21:30

1 Answers1

2

Notice the little number in the top-left corner of the axes that says -3.199e1? This tells you the y value of the line is whatever is specified by the apparent y coordinate, plus -31.99. Since you did not specify the limits of the y axis, matplotlib calculated them automatically from the data, and zoomed in to this level, your data is not constant.

Your data looks like a constant line when you specify the y limits:

plt.plot(energy_list)
plt.ylim(-34, -30)

enter image description here

If you'd rather not hardcode these limits, you can just add/subtract a set value to the max/min of the data:

upper_lim = round(max(energy_list) + 2)
lower_lim = round(min(energy_list) - 2)
plt.ylim(lower_lim, upper_lim)
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70