I am plotting a pandas DataFrame with several columns as below:
fig, ax = py.subplots(figsize=(11.7, 8.3))
df.plot(ax=ax, secondary_y=[A])
I can format the primary yaxis with a command as below:
ax.yaxis.set_major_formatter(FormatStrFormatter('%d days'))
How can I apply formatting to the secondary Y-axis (the one that displays on the right)?
You can access the secondary ax with ax.right_ax
. See the pandas docs on this: http://pandas.pydata.org/pandas-docs/stable/visualization.html#selective-plotting-on-secondary-y-axis.
So you can do like this:
ax.right_ax.yaxis.set_major_formatter(FormatStrFormatter('%d days'))
Using matplotlib, you can also access it as ax.twinx()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With