用图中的数字替换列字符串

Replacing column strings with numbers in a plot

有什么方法可以指定列号作为索引显示在 x 轴上吗?考虑以下数据框

      Metric Value Metric Value Metric Value Metric Value
0             3            3            7            7
1             1            1            1            1
2             0            0            0            0

下面的代码绘制了 row[0],但是,如您所见,“metric Value”写在 x 点上。我想改为查看 1、2、3、4。

    row = df.iloc[0]
    row.astype(int).plot()
    plt.show()
    

试试这个:

df.columns = range(1, len(df.columns)+1)
row = df.iloc[0]
row.astype(int).plot()
plt.show()