I'm trying to create a simple 1 by 3 subplot of the maps I have. They only have 2 dimensions (longitude and latitude) after time averaging. The final map plots perfectly, but the first two subplots are just blank. Thanks in advance for any advice!
import numpy as np
import xarray as xa
import cmocean.cm as cm
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
lgm = xa.open_dataset('lgm.nc', decode_times=False)
pre = xa.open_dataset('pre-i.nc', decode_times=False)
pd = xa.open_dataset('present.nc', decode_times=False)
def pco2_diff():
lgm_pco2 = lgm.O_pco2sur
pre_pco2 = pre.O_pco2sur
pd_pco2 = pd.O_pco2sur
#-------------------------Time averaged data-------------------------------
lgm_pco2_mean = lgm_pco2.mean("time")
pre_pco2_mean = pre_pco2.mean("time")
pd_pco2_mean = pd_pco2.mean("time")
#-----------------Get the ocean-atmosphere fluxes--------------------------
lgm_pco2_diff = lgm_pco2_mean - 189.65
pre_pco2_diff = pre_pco2_mean - 277.44
pd_pco2_diff = pd_pco2_mean - 368.89
#---------------------Basic plots, 1 at a time-----------------------------
lgm_pco2_diff.plot()
pre_pco2_diff.plot()
pd_pco2_diff.plot()
#-----------------------------Subplots-------------------------------------
f, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True, sharex=False)
#1 row, 3 columns, sharing the y-axis, not sharing the x-axis
ax1 = lgm_pco2_diff.plot(vmin=-300, vmax=300, add_colorbar=False)
ax2 = pre_pco2_diff.plot(vmin=-300, vmax=300, add_colorbar=False)
ax3 = pd_pco2_diff.plot(vmin=-300, vmax=300,cmap=cm.thermal)
Maybe try the following:
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True, sharex=False)
ax1.plot(lgm_pco2_diff, vmin=-300, vmax=300, add_colorbar=False)
ax2.plot(pre_pco2_diff, vmin=-300, vmax=300, add_colorbar=False)
ax3.plot(pd_pco2_diff, vmin=-300, vmax=300, cmap=cm.thermal)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.