Formatting the secondary y axis in pandas

I am drawing a pandas DataFrame with multiple columns as shown below:

fig, ax = py.subplots(figsize=(11.7, 8.3)) df.plot(ax=ax, secondary_y=[A]) 

I can format the primary yaxis with the command as shown below:

 ax.yaxis.set_major_formatter(FormatStrFormatter('%d days')) 

How to apply formatting to the secondary Y axis (the one displayed on the right)?

+6
source share
1 answer

You can access the background tone with ax.right_ax . See pandas docs on this subject: http://pandas.pydata.org/pandas-docs/stable/visualization.html#selective-plotting-on-secondary-y-axis .
So you can do the following:

 ax.right_ax.yaxis.set_major_formatter(FormatStrFormatter('%d days')) 

Using matplotlib, you can also access it as ax.twinx()

+5
source

Source: https://habr.com/ru/post/951112/


All Articles