在 pandas 中格式化辅助 y 轴 [英] formatting secondary y axis in pandas
问题描述
我正在绘制一个包含以下几列的 Pandas DataFrame:
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])
我可以使用如下命令格式化主 yaxis:
I can format the primary yaxis with a command as below:
ax.yaxis.set_major_formatter(FormatStrFormatter('%d days'))
如何将格式应用于辅助 Y 轴(显示在右侧的轴)?
How can I apply formatting to the secondary Y-axis (the one that displays on the right)?
推荐答案
您可以使用 ax.right_ax
访问辅助斧.请参阅熊猫文档:http://pandas.pydata.org/pandas-docs/stable/visualization.html#selective-plotting-on-secondary-y-axis.
所以你可以这样做:
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'))
使用 matplotlib,你也可以通过 ax.twinx()
Using matplotlib, you can also access it as ax.twinx()
这篇关于在 pandas 中格式化辅助 y 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!