我不知道如何得到一个Map,就像所附的例子,但没有海岸线,边界和网格线以外的绘制数据。第二个问题是,而不是一个正方形框架与经度和纬度标签,是否有可能设置x和y轴沿着绘制数据的轮廓,使标签是旁边的这个轮廓,而不是旁边的框架?
import xarray as xr
from matplotlib import pyplot as plt
import cartopy.crs as ccrs
import cartopy
ds = xr.open_dataset(r'D:\Python\qq_z1000.nc')
ds2 = ds['qq'].mean(dim='time')
minn = ds2.min()
maxx = ds2.max()
fig = plt.figure(figsize=(8, 8), dpi=300, num="False")
central_lon, central_lat = 12.5, 47.5
extent = [-22.5, 45, 25, 65]
ax = plt.axes(projection=ccrs.Orthographic(central_lon, central_lat))
ax.set_extent(extent)
gl = ax.gridlines(draw_labels=True, linestyle='--', color='grey', dms=True,
x_inline=False, y_inline=False, linewidth=0.3)
gl.top_labels = False
gl.right_labels = False
gl.xlabel_style = {'size': 10, 'color': 'black'}
gl.ylabel_style = {'size': 10, 'color': 'black'}
gl.xlocator = plt.FixedLocator(range(-180, 181, 10))
ax.coastlines(resolution='50m')
ax.add_feature(cartopy.feature.BORDERS, edgecolor='black')
im = ax.pcolormesh(ds2.longitude, ds2.latitude, ds2, transform=ccrs.PlateCarree(),
cmap='jet', vmin=minn, vmax=maxx)
cbar = fig.colorbar(im, orientation='horizontal', pad=0.05, shrink=0.8)
#plt.savefig('my_map2.jpg', dpi=300, bbox_inches='tight')
plt.show()
我尝试过用不同的方法更改代码中的这一行,但都无济于事。im = ax.pcolormesh(ds2.longitude, ds2.latitude, ds2, transform=ccrs.PlateCarree(), cmap='jet', vmin=minn, vmax=maxx)
1条答案
按热度按时间5jvtdoz21#
我设法纠正了代码,得到了我想要的Map。
enter image description here