首页 文章

如何使用MatPlotLib绘制两个DataFrame?

提问于
浏览
1

我有两个DataFrame northsouth . 每个都有相同的行和列 . 我想在一个图中将两个DataFrame的速度列绘制为条形图 . 我正在尝试这个:

ax = south['speed'].plot(kind='bar', color='gray')
north['speed'].plot(kind = 'bar', color='red', ax=ax)
plt.show()

但它仅绘制了最后一个数据帧,即只有 north DataFrame . 你能帮助我吗?

1 回答

  • 1

    1)如果你想只绘制'速度'列,你必须连接数据帧,如:

    df = pd.concat([north, south])
    

    要么

    df = north.append(south)
    

    2)如果您想比较两个数据帧的“速度”列,您必须沿轴= 1连接数据帧,如:

    df = pd.concat([north, south], axis=1, ignore_index=True)
    

    df 的调用绘图方法 .

    欲了解更多信息:https://pandas.pydata.org/pandas-docs/stable/merging.html

相关问题