Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用次y轴绘制分组数据_Python_Matplotlib_Plot_Pandas - Fatal编程技术网

Python 使用次y轴绘制分组数据

Python 使用次y轴绘制分组数据,python,matplotlib,plot,pandas,Python,Matplotlib,Plot,Pandas,我想绘制12个图形(每月一个图形),包括左y轴上的列'A'和'B',以及右y轴上的列'C' 下面的代码将在左侧绘制所有内容 将熊猫作为pd导入 索引=pd.日期范围('2011-1-1 00:00:00','2011-12-31 23:50:00',频率为'1h') df=pd.DataFrame(np.random.rand(len(index),3),columns=['A','B','C'],index=index) df2=df.groupby(λx:x.month) 对于键,df2中的

我想绘制12个图形(每月一个图形),包括左y轴上的列
'A'
'B'
,以及右y轴上的列
'C'

下面的代码将在左侧绘制所有内容

将熊猫作为pd导入
索引=pd.日期范围('2011-1-1 00:00:00','2011-12-31 23:50:00',频率为'1h')
df=pd.DataFrame(np.random.rand(len(index),3),columns=['A','B','C'],index=index)
df2=df.groupby(λx:x.month)
对于键,df2中的组:
group.plot()

如何分隔列并使用如下内容:
group.plot({'A','B':style='g'},{'C':secondary_y=True})

您可以捕获Pandas
plot()
命令返回的轴,并再次使用它在右轴上绘制
C

index=pd.date_range('2011-1-1 00:00:00', '2011-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)

df2 = df.groupby(lambda x: x.month)
for key, group in df2:
    ax = group[['A', 'B']].plot()
    group[['C']].plot(secondary_y=True, ax=ax)

要获取单个图例中的所有行,请参见:

你知道为什么每个月的x记号不同吗?特别是二月。