我被困在这里了。 我的代码:
import os
import matplotlib.pyplot as plt
from netCDF4 import Dataset as netcdf_dataset
import numpy as np
from cartopy import config
import cartopy.crs as ccrs
fname = os.path.join("path", "file")
dataset = netcdf_dataset(fname)
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
IVT = dataset.variables['IVT'][0,:,:]
IVTm = dataset.variables['IVTm'][0,:,:]
ax = plt.axes(projection=ccrs.PlateCarree())
map_ivt=ax.contourf(lons, lats, IVT, 60,
transform=ccrs.PlateCarree())
map_ivt=ax.contourf(lons, lats, IVTm, 60,
transform=ccrs.PlateCarree())
plt.colorbar(map_ivt, orientation='horizontal')
ax.coastlines()
ax.gridlines()
plt.show()
这是我的结果(我认为我的调色板没有显示正确的值,两个变量的值都超过800):
无法找到在同一地图上绘制“IVT”和“IVTm”的正确方法,如下面的示例所示(IVT为红色,IVTm为蓝色):
我需要用一个调色板绘制这两个量,就像示例中那样,这个调色板是双向的
多谢各位
为了在对
contourf
的两个单独调用中实现这一点,您必须为某些值创建一个alpha为0的自定义colormap,这似乎需要大量的工作。如果这些值真的不重叠,这里最简单的方法是将它们组合成一个数组,并用contourf
绘图:相关问题 更多 >
编程相关推荐