【问题标题】:Python - subplot only displaying the bottom plotPython - 子图仅显示底部图
【发布时间】:2020-05-09 13:35:03
【问题描述】:

我有一个问题,Python 在底部子图中将数据集绘制为“ax1”,而不是在任何地方绘制“ax2”数据,从而使顶部子图为空白。

任何帮助表示赞赏!

fig, (ax1, ax2) = plt.subplots(2, sharex=True)
    fig.suptitle('Sea Surface pCO2 (ppmv)')
    ax1 = ax1.plot(interp_bathy.where(interp_bathy > 0).plot(cmap=cm.topo, vmin = -4000, vmax = 4000, add_colorbar=False),interp_pco2_pre.where(interp_bathy >-120).where(interp_bathy <0).plot(levels=np.arange(200,501,10), cmap=cm.thermal, cbar_kwargs = {'label':'Sea surface pCO2 (ppmv)'}))
    ax2 = ax2.plot(interp_bathy.where(interp_bathy > 0).plot(cmap=cm.topo, vmin = -4000, vmax = 4000, add_colorbar=False),interp_pco2_pd.where(interp_bathy >-120).where(interp_bathy <0).plot(levels=np.arange(200,501,10), cmap=cm.thermal, cbar_kwargs = {'label':'Sea surface pCO2 (ppmv)'}))

【问题讨论】:

    标签: python subplot


    【解决方案1】:

    我认为您需要了解ax.plotpandas.Series.plot 的作用。这样做的方法是将轴传递给pandas.Series.plot 函数。相反,您将绘制的实例传递给 ax.plot 本身,这没有意义。

    尝试执行以下操作:

    data1.plot(otherparams.., ax=ax1)
    data2.plot(otherparams.., ax=ax2)
    

    在你的情况下,它可能是这样的:

    dataset1 = interp_bathy.where(interp_bathy > 0)
    dataset2 = interp_pco2_pre.where(interp_bathy > -120).where(interp_bathy < 0)
    dataset3 = interp_pco2_pd.where(interp_bathy > -120).where(interp_bathy < 0)
    
    dataset1.plot(cmap=cm.topo, vmin = -4000, vmax = 4000,
        add_colorbar=False, ax=ax1)
    dataset2.plot(levels=np.arange(200,501,10), cmap=cm.thermal,
        cbar_kwargs = {'label':'Sea surface pCO2 (ppmv)'}, ax=ax1)
    dataset1.plot(cmap=cm.topo, vmin = -4000, vmax = 4000,
        add_colorbar=False, ax=ax2)
    dataset3.plot(levels=np.arange(200,501,10), cmap=cm.thermal,
        cbar_kwargs = {'label':'Sea surface pCO2 (ppmv)'}, ax=ax2)
    

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 2015-12-28
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 1970-01-01
      相关资源
      最近更新 更多