我尝试使用cartopy自定义较长垂直尺寸的子图,但仍然无法弄清楚如何增加每个图的高度(垂直高度)。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import xarray as xr
import numpy as np
import matplotlib.ticker as mticker
# Load available datasets
ds=xr.tutorial.load_dataset("air_temperature")
# Get 6 maps (images)
air=[ds.air.isel(time=i) for i in range(7)]
# Specify crs
proj = ccrs.PlateCarree() #ccrs.Orthographic()
# Set size and number of plots
fig,axes = plt.subplots(ncols=3,nrows=2,figsize=(20,7),
subplot_kw={'projection': proj},gridspec_kw = {'wspace':0.2, 'hspace':0.007})
# Zip maps and axes and index
mzip=zip(air,[y for x in axes for y in x])
# Loop over the maps and axes
for img, ax in mzip:
# Add countries
ax.add_feature(cfeature.BORDERS, facecolor="green")
# plot maps/images
temp=img.plot.contourf(ax=ax,transform=proj,cmap="magma",vmax=300,vmin=220, add_colorbar=False)
# Create gridlines
gl = ax.gridlines(crs=proj, linewidth=1, color='black', alpha=0.2, linestyle="--")
# Manipulate gridlines number and spaces
gl.ylocator = mticker.FixedLocator(np.arange(-90,90,20))
gl.xlocator = mticker.FixedLocator(np.arange(-180, 180, 25))
gl.xlabels_top = False
gl.xlabels_bottom = True
gl.ylabels_left = True
gl.ylabels_right = False
plt.show()
字符串
的数据
1条答案
按热度按时间50pmv0ei1#
您可以在创建子图时添加
aspect
关键字。但正如乔迪·克利马克(Jody Klymak)已经暗示的那样,也许选择不同的投影会更好?但添加例如:
subplot_kw={'projection': proj, "aspect": 2}
个我稍微改变了你的例子:
字符串
结果:
的数据