如何使用pandas和matplotlib将索引打印为axis_x?

时间:2019-01-21 18:22:13

标签: python pandas dataframe

我有三个数据框,我想用图形表示它们,其中column(0)是索引:

data1 = pd.DataFrame({'timestamp':['00:00:01','00:00:06','00:00:27'], 'users':[1364,1236,1532]}

data2 = pd.DataFrame({'timestamp':['00:00:00','00:00:04','00:00:05', 00:00:07],'original':[100,200,300, 400]})  

data3 = pd.DataFrame({'timestamp':['00:00:00','00:00:04','00:00:05', 00:00:07],'op1':[7000,7000,7000, 7000], 'op2':[28000,28000,28000, 28000]})  

这是python中的代码

def graph_information(data1, data2, data3):
    fig, ax = plt.subplots(facecolor='white')
    plt.xticks(rotation=90)
    ax.set_xlabel('T')
    ax.set_ylabel('R')
    ax.set_facecolor('white')   
    ax.spines['bottom'].set_color('black')
    ax.spines['top'].set_color('black') 
    ax.spines['right'].set_color('black')
    ax.spines['left'].set_color('black')

    data1.plot(ax=ax, figsize=(20,10), legend=False)
    data3.plot(ax=ax, color=['orange','red'], linewidth=5, legend=False)
    data2.plot(ax=ax, secondary_y=True, color='black', linewidth=3, legend=False)
    plt.show() 

此外,由于我无法打印姓名,secondary_y无法正常工作。

另外,我尝试了这个:

data1.plot(ax = ax,figsize =(20,10),图例= False,x = data1.index.values)

但是,它不起作用

0 个答案:

没有答案