11

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

ChrisF
  • 134,786
  • 31
  • 255
  • 325
dreamwalker
  • 1,693
  • 3
  • 18
  • 23

1 Answers1

14

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

joris
  • 133,120
  • 36
  • 247
  • 202