我使用下面的代码绘制了GPP的全球Map:
('lon'和'lat'都是netCDF4属性,分别具有(144,)和(90,)的形状,而'gpp_avg'是具有(90,144)形状的numpy数组)
import numpy as np
import netCDF4 as n4
import matplotlib.pyplot as plt
import cartopy as cart
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from mpl_toolkits.basemap import Basemap
>> gpp_avg = n4.Dataset('decadal_gpp.nc', 'r')
>> lon = gpp_avg.variables['lon'] # 144 grid cells every 2.5 degrees (east-west)
>> lat = gpp_avg.variables['lat'] # 90 grid cells every 2 degrees (north-south)
>> # Plotting data on a map with Cartopy
>> plt.figure()
>> ax = plt.axes(projection=ccrs.PlateCarree())
>> ax.coastlines() # Adding coastlines
>> ax.add_feature(cart.feature.OCEAN, zorder=100, edgecolor='k')
>> cs = ax.contourf(lon[:], lat[:], gpp_avg[:], cmap = 'Spectral')
>> cbar = plt.colorbar(cs, ax=ax) # Additional necessary information
>> cbar.set_label('g[C]/m^2/day')
>> gridl = ax.gridlines(color="black", linestyle="dotted",
draw_labels=True) # Adding axis labels - latitude & longitude
>> gridl.xformatter=LONGITUDE_FORMATTER
>> gridl.yformatter=LATITUDE_FORMATTER
>> gridl.xlabels_top = False
>> gridl.ylabels_right = False
>> plt.show()
我有一个numpy数组'ci_95_gpp',它的形状为(90,144),其中包含全局Map每个网格单元的p值。我想在全局等值线图的顶部绘制p值大于2的点。
我该怎么做呢?非常感谢。
1条答案
按热度按时间cx6n0qe31#
我在CartopyMap上生成一组等高线图数据。用于轮廓绘制的数据点被分成2组,具有负z值和正z值。Numpy
maskedarray
用于该操作。我希望这对一般读者,包括OP,都有帮助。结果图: