Skip to content Skip to sidebar Skip to footer

Why Does Matplotlib Require Setting Log Scale Before Plt.scatter() But Not Plt.plot()?

I found out in this helpful answer that plt.scatter() and plt.plot() behave differently when a logrithmic scale is used on the y axis. With plot, I can change to log any time bef

Solution 1:

This somehow has to do with the the display area (axes limits) calculated by matplotlib.

This behaviour is fixed by manually editing the axes range by using set_xlim and set_ylim methods.

plt.figure()
plt.scatter(X, Y)
plt.yscale('log')
plt.xscale('log')
axes = plt.gca()
axes.set_xlim([min(X),max(X)])
axes.set_ylim([min(Y),max(Y)])
plt.show()

Image

The exact reason of this behavior is however not yet figured out by me. Suggestions are welcomed.

EDIT

As mentioned in comments section, apparently Matplotlib has identified Autoscaling has fundamental problems as a Release Critical Issue on their official Github repo, which would be fixed in upcoming versions. Thanks.

Post a Comment for "Why Does Matplotlib Require Setting Log Scale Before Plt.scatter() But Not Plt.plot()?"