【问题标题】:How to create multiple plots where each series is in a different figure?如何创建多个图,其中每个系列都在不同的图中?
【发布时间】:2015-02-17 15:50:01
【问题描述】:

我在试图弄清楚如何在 python 中绘制多个数字时遇到了麻烦。我有两个数据框,在每个数据框中我有两列。因此,我想要总共 4 个地块,可能都在一行和 4 列中?或全部为 2 行 2 列。我尝试了以下技巧:

    actuals = ['Acttemplow','acttemphi']
    fig,axes = plt.subplots(nrows=1,ncols=4,figsize=(12,4))
    for i,var in enumerate(actuals):
        ny_winter_dat[var].plot(ax=axes[i],title='ny winter ' + var)
        il_winter_dat[var].plot(ax=axes[i],title='illonois winter ' + var)

但是在实施上述算法后,我得到了两个系列的两个数字的图。其他两个数字是空白的。我没有在不同的盒子里得到不同的系列。我尝试更改 nrows=2 和 ncols=4 但仍然无法弄清楚。有人可以帮忙吗?谢谢

【问题讨论】:

标签: python pandas plot


【解决方案1】:

axes 是一个形状为 1,4 的 ndarray

你的循环是:

  • ny_winter_dat[Acttemplow] in ax #0
  • il_winter_dat[Acttemplow] in ax #0
  • ny_winter_dat[acttemphi] in ax #1
  • il_winter_dat[acttemphi] in ax #1

你想要的:

  • ny_winter_dat[Acttemplow] in ax #0
  • il_winter_dat[Acttemplow] in ax #2
  • ny_winter_dat[acttemphi] in ax #1
  • il_winter_dat[acttemphi] in ax #3

actuals = ['Acttemplow','acttemphi'] fig,axes = plt.subplots(nrows=1,ncols=4,figsize=(12,4)) for i,var in enumerate(actuals): ny_winter_dat[var].plot(ax=axes[i],title='ny winter ' + var) il_winter_dat[var].plot(ax=axes[i+2],title='illonois winter ' + var)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    相关资源
    最近更新 更多