pandas 在熊猫中格式化辅助 y 轴
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/18077905/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
formatting secondary y axis in pandas
提问by dreamwalker
I am plotting a pandas DataFrame with several columns as below:
我正在绘制一个包含以下几列的 Pandas DataFrame:
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:
我可以使用如下命令格式化主 yaxis:
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)?
如何将格式应用于辅助 Y 轴(显示在右侧的轴)?
采纳答案by joris
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。请参阅Pandas文档:http: //pandas.pydata.org/pandas-docs/stable/visualization.html#selective-plotting-on-secondary-y-axis。
所以你可以这样做:
ax.right_ax.yaxis.set_major_formatter(FormatStrFormatter('%d days'))
Using matplotlib, you can also access it as ax.twinx()
使用 matplotlib,您还可以将其作为 ax.twinx()

