import matplotlib.pyplot as plt import numpy as np import netCDF4 as nc from matplotlib.font_manager import FontProperties from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER import matplotlib.ticker as mticker import matplotlib as mpl import cartopy.crs as ccrs import cartopy.feature as cfeat from wrf import getvar, to_np import cmaps Simsun = FontProperties(fname="./font/SimSun.ttf") Times = FontProperties(fname="./font/Times.ttf") config = { "font.family":'serif', "mathtext.fontset": 'stix', "font.serif": ['SimSun'], } mpl.rcParams.update(config) mpl.rcParams['axes.unicode_minus']=False fig=plt.figure(figsize=(5,5),dpi=150) axe=plt.subplot(1,1,1,projection=ccrs.PlateCarree()) axe.set_title('湿度$\mathrm{(2m)}$',fontsize=12,y=1.05) axe.add_feature(cfeat.COASTLINE.with_scale('10m'), linewidth=1,color='k') LAKES_border = cfeat.NaturalEarthFeature('physical', 'lakes', '10m', edgecolor='k', facecolor='never') axe.add_feature(LAKES_border, linewidth=0.8) axe.set_extent([119.2,122.3, 29.7, 32.8], crs=ccrs.PlateCarree()) gl = axe.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=0.8, color='gray',linestyle=':') gl.top_labels,gl.bottom_labels,gl.right_labels,gl.left_labels = False,False,False,False gl.xlocator = mticker.FixedLocator(np.arange(119.5, 122.1, 0.5)) gl.ylocator = mticker.FixedLocator(np.arange(30, 32.6, 0.5)) axe.set_xticks(np.arange(119.5, 122.1, 0.5), crs=ccrs.PlateCarree()) axe.set_yticks(np.arange(30, 32.6, 0.5), crs=ccrs.PlateCarree()) axe.xaxis.set_major_formatter(LongitudeFormatter()) axe.yaxis.set_major_formatter(LatitudeFormatter()) axe.tick_params(labelcolor='k',length=5) labels = axe.get_xticklabels() + axe.get_yticklabels() [label.set_fontproperties(FontProperties(fname="./font/Times.ttf",size=8)) for label in labels] ncfile=nc.Dataset('D:\wrf_simulation\\2meic\\wrfout_d03_2016-07-21_12_2meic') rh2=getvar(ncfile,'rh2',timeidx=126) lat=getvar(ncfile,'lat') lon=getvar(ncfile,'lon') rh2_level=np.arange(50,110,10) contour = axe.contour(lon, lat, rh2, levels=rh2_level, colors='blue', linewidths=1, linestyles='-',alpha=1) axe.clabel(contour, inline=True, fontsize=8, colors='red', fmt='%1.0f',manual=False) plt.show()