""" 空白底图 20221225 """ 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 cf from wrf import getvar, to_np import cmaps Simsun = FontProperties(fname="D:/Byp/Information/SS/Programming/Python/SimHei.ttf") Times = FontProperties(fname="D:/Byp/Information/SS/Programming/Python/times.ttf") config = { "mathtext.fontset": 'stix', } mpl.rcParams.update(config) mpl.rcParams['axes.unicode_minus'] = False fig = plt.figure(figsize=(4, 4), dpi=150) axes = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree()) axes.set_title('温度$\mathbf{(2m)}$', fontproperties=Simsun, fontsize=9, loc='center', y=0.98) lon_min, lon_max, lat_min, lat_max = 110, 135, 15, 40 axes.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree()) # 添加地物############################################################### axes.add_feature(cf.COASTLINE.with_scale('10m'), lw=0.4) # axes.add_feature(cf.LAKES.with_scale('110m'), linewidth=1, color='k') # axes.add_feature(cf.RIVERS.with_scale('110m'), lw=0.4) # axes.add_feature(cf.LAND.with_scale('110m')) # axes.add_feature(cf.OCEAN.with_scale('110m')) # axes.add_feature(cf.BORDERS.with_scale('10m'), lw=0.4) # axes.add_feature(cf.STATES.with_scale('110m')) ################################################################ # 添加坐标############################################################### gl = axes.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linestyle=":", linewidth=0.3, x_inline=False, y_inline=False, color='gray') gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, True, False, True # gl.xformatter = LONGITUDE_FORMATTER # 使横坐标转化为经纬度格式 无效 # gl.yformatter = LATITUDE_FORMATTER gl.xlocator = mticker.FixedLocator(np.arange(lon_min, lon_max, 2.5)) # 设置坐标轴范围和间隔 gl.ylocator = mticker.FixedLocator(np.arange(lat_min, lat_max, 2.5)) gl.xlabel_style = {'size': 4} # 修改经纬度字体大小 gl.ylabel_style = {'size': 4} # labels = axes.get_xticklabels() + axes.get_yticklabels() # [label.set_fontproperties(FontProperties(fname="D:/Byp/Information/SS/Programming/Python/times.ttf", size=8)) for label in labels] # axes.set_xticks(np.arange(110, 130+4, 4), crs=ccrs.PlateCarree()) # axes.set_yticks(np.arange(20, 40+4, 4), crs=ccrs.PlateCarree()) ################################################################ plt.subplots_adjust(wspace=0.1) plt.show()