Home > Software engineering >  matplotlib symlog malfunctions when using pandas
matplotlib symlog malfunctions when using pandas

Time:10-13

Plotting with a symmetric log scale using pandas gives excessively wide axis limits.

Set up some dummy data and make a plot:

>>> x = [0, 1]
>>> y = [-11825.251019, -470.310618]
>>> plt.plot(x, y)
>>> plt.yscale('symlog')
>>> plt.ylim()
(-13894.13926670043, -400.27964366818765)

So far, so good. Now try the same thing with pandas:

>>> pd.Series(y).plot()
>>> plt.yscale('symlog')
>>> plt.ylim()
(-12392.998039049999, 97.43640205000008)

Why is the upper axis limit positive?

CodePudding user response:

Series.plot has the logy parameter, and using logy='sym' produces the same ylimits as pure matplotlib.

pd.Series(y).plot(logy='sym')
  • Related