Python - 子图仅显示底部图
Python - subplot only displaying the bottom plot
我有一个问题 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)'}))
我认为您需要了解 ax.plot and pandas.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)
我有一个问题 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)'}))
我认为您需要了解 ax.plot and pandas.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)