10

For some reason, plt.autoscale does not seem to work for very small values (i.e. something like 1E-05). Everything is just displayed close to the zero axis in the graph as shown.

Any ideas where I am going wrong here?

import matplotlib.pyplot as plt

y=  [1.09E-05,  1.63E-05,   2.45E-05,   3.59E-05,   5.09E-05,   6.93E-05,   9.07E-05]
x=  [0, 10, 20, 30, 40, 50, 60]

fig3, ax3 = plt.subplots()
ax3.scatter(x, y, color='k', marker = "o")
ax3 = plt.gca()
plt.autoscale(enable=True, axis="y", tight=False)
plt.show()

enter image description here

bwrr
  • 611
  • 1
  • 7
  • 16

2 Answers2

15

I believe this is a known issue which is still not solved in matplotlib. It is the same as here or here.

Possible solutions for this case would be

Use plot instead of scatter.

import matplotlib.pyplot as plt

y=  [1.09E-05,  1.63E-05,   2.45E-05,   3.59E-05,   5.09E-05,   6.93E-05,   9.07E-05]
x=  [0, 10, 20, 30, 40, 50, 60]

fig3, ax3 = plt.subplots()
ax3.plot(x, y, color='k', marker = "o", ls="")
ax3.autoscale(enable=True, axis="y", tight=False)
plt.show()

Use invisible plot in addition to scatter

import matplotlib.pyplot as plt

y=  [1.09E-05,  1.63E-05,   2.45E-05,   3.59E-05,   5.09E-05,   6.93E-05,   9.07E-05]
x=  [0, 10, 20, 30, 40, 50, 60]

fig3, ax3 = plt.subplots()
ax3.scatter(x, y, color='k', marker = "o")
ax3.plot(x, y, color='none')
ax3.relim()
ax3.autoscale_view()
plt.show()

Manually scale the axis using set_ylim.

import matplotlib.pyplot as plt

y=  [1.09E-05,  1.63E-05,   2.45E-05,   3.59E-05,   5.09E-05,   6.93E-05,   9.07E-05]
x=  [0, 10, 20, 30, 40, 50, 60]

fig3, ax3 = plt.subplots()
ax3.scatter(x, y, color='k', marker = "o")

dy = (max(y) - min(y))*0.1
ax3.set_ylim(min(y)-dy, max(y)+dy)
plt.show()
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • I did not know this was already asked before. Thank you for providing an informative answer nonetheless! – bwrr Aug 18 '17 at 13:25
1

Just to add an update here to anyone who finds this post in the future - it has now been resolved in matplotlib 3.2.1. Just update your package and it should work.

jpmorr
  • 500
  • 5
  • 25
  • I tried this with my data and I got the same result as @bwrr. The solution for me was to use plot (is mentioned by @ImportanceOfBeingErnest) instead of scatter, with parameters `marker = "o", ls=""` Not sure if this issue has been fixed in matplotlib for scatter? – Bernard Esterhuyse Jun 05 '20 at 10:09