Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

formatting secondary y axis in pandas

Tags:

pandas

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)?

like image 309
dreamwalker Avatar asked Aug 06 '13 10:08

dreamwalker


1 Answers

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()

like image 152
joris Avatar answered Oct 05 '22 12:10

joris