0

I have an issue with Python plotting the data set as 'ax1' on the bottom subplot, and not plotting the 'ax2' data anywhere, leaving the top subplot blank.

Any help appreciated!

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)'}))

1 Answer 1

1

I think you need to understand what ax.plot and pandas.Series.plot do. The way to do this would be to pass the axes to the pandas.Series.plot function. Instead, you are passing the plotted instance to ax.plot itself, which doesn't make sense.

Try doing the following:

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

In your case, it would probably be like:

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.