Pandas groupby函数中的secondary_y范围 - python

我想在一个简单的示例中更改辅助Y轴的范围:

MWE:

index=pd.date_range('2014-1-1 00:00:00', '2014-12-31 23:50:00', freq='1h')
df=pd.DataFrame(np.random.randn(len(index),3).cumsum(axis=0),columns=['A','B','C'],index=index)

df_month = df.groupby(lambda x: x.month)
df_month.plot(secondary_y=['C'],mark_right=False)

groupby.plot功能中,我只能为左轴设置ylim。如何更改右轴范围?

我也尝试遍历groupby中的键:

for key, group in df_month:
    ax = group[['A','B']].plot()
    fig= group[['C']].plot(secondary_y=True, ax=ax, mark_right=False)

使用ax2 = ax1.twinx()变体,但没有成功。

python大神给出的解决方案

熊猫绘图功能返回一个轴数组,您可以使用ax.right_ax从每个轴中获取右轴。

axs = df_month.plot(secondary_y=['C'], mark_right=False)

for ax in axs:
    ax.right_ax.set_ylim((0,50)) # Set the y limits to 0 to 50