python - Matplotlib.pyplot 只显示最终图
问题描述
我正在尝试为我拥有的地图创建一个简单的 1 x 3 子图。在时间平均之后,它们只有 2 个维度(经度和纬度)。最终的地图绘制完美,但前两个子图只是空白。提前感谢您的任何建议!
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)
解决方案
也许尝试以下方法:
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)
推荐阅读
- c# - AutoMapper:一对多 -> 一对一
- postgresql - 无法在带有 M1 芯片的 Mac 上使用“persistent-postgresql”构建 Haskell 项目
- javascript - Javascript:查询 API 循环
- excel - 将工作表中的数据范围作为新的 csv 文件传输到专用目录中
- kotlin - Janusgraph Kotlin“选择”步骤是什么类型的?
- r - R:网络抓取返回错误的产品价格
- django - 如何在 django 中过滤这个?
- amazon-web-services - 如何从 AWS Fargate Docker 容器访问主机 IP 地址
- python - 使用 Jupyter notebook - 哪个最适合这个 tkinter 算法?quit()、exit()、sys.exit() 还是 os.exit()?
- r - R比较两个数据集中每一行的重复值