【问题标题】:subplot with pandas dataframes带有熊猫数据框的子图
【发布时间】:2015-01-26 15:59:42
【问题描述】:

我想使用 pandas 数据框(称为 df)在图形上创建多个子图。

我原来的情节在这里:

df.plot(x='month', y='number', title='open by month',color="blue")

我在本网站pyplot tutorial from matplotlib的“处理图形和子图”部分尝试了多次尝试

[1]

plt.figure(1)
df.plot.(figure(1), sublot(211), x='month', y='number', title='open byXXX"
df.plot.(figure(1), sublot(212), x='month', y='number', title='open byXXX"

[2]

plt.figure(1)
df.plot.subplot(211)(x='month', y='number', title='open byXXX")
df.plot.subplot(212)(x='month', y='number', title='open byXXX")

【问题讨论】:

    标签: python matplotlib pandas subplot


    【解决方案1】:

    你的阴谋是针对轴,而不是数字。 Pandas 确实与绘图/matplotlib 无关。为了方便,Pandas 开发人员只是简单地向 matplotlib 添加了一个快速界面。

    你真的应该学会使用 matplotlib 而不是先通过 pandas。但是对于您手头的问题,您只需将 Axes 对象传递给数据框的 plot 方法。

    fig, axes = plt.subplots(nrows=2, ncols=1)
    df1.plot(..., ax=axes[0, 0])
    df2.plot(..., ax=axes[1, 0])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-31
      • 2021-06-02
      • 2015-07-08
      • 2021-08-28
      • 2016-03-28
      • 2019-06-24
      • 2020-10-10
      相关资源
      最近更新 更多