在 Matplotlib 中并排绘制等高线图?

Plotting contour maps side by side in Matplotlib?

我有两张不同年份的印度降水量等高线图,我希望它们能够以相同的功能打印,最好并排打印。我不知道该怎么做。

地图A =

height = width/1.666

fig = plt.figure(figsize=(width,height))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.coastlines()
ax.gridlines()
ax.set_extent([66, 96, 4, 33])

ax.add_feature(cfeature.BORDERS)

ax.plot(77.2, 28.6, 'ro', markersize=7, transform=ccrs.Geodetic())
ax.text(77.2, 28.6, '   New Delhi', transform=ccrs.Geodetic())  
ax.plot(72.87, 19.07, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(72.87, 19.07, '   Mumbai', transform=ccrs.Geodetic()) 
ax.plot(77.59, 12.97, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(77.59, 12.97, '   Bangalore', transform=ccrs.Geodetic())  

cs= ax.contourf(lonind, latind, tind1988, transform=ccrs.PlateCarree(), cmap = 'BuPu')
cbar= plt.colorbar(cs)
cbar.ax.set_ylabel(r"$Rainfall-(mm/day)$",rotation =270, labelpad=20, fontsize=14)

plt.show()


地图B =

fig = plt.figure(figsize=(width,height))

ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.coastlines()
ax.gridlines()
ax.set_extent([66, 96, 4, 33])

ax.add_feature(cfeature.BORDERS)

ax.plot(77.2, 28.6, 'ro', markersize=7, transform=ccrs.Geodetic())
ax.text(77.2, 28.6, '   New Delhi', transform=ccrs.Geodetic())  
ax.plot(72.87, 19.07, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(72.87, 19.07, '   Mumbai', transform=ccrs.Geodetic()) 
ax.plot(77.59, 12.97, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(77.59, 12.97, '   Bangalore', transform=ccrs.Geodetic()) 

cs= ax.contourf(lonind, latind, tind2018, transform=ccrs.PlateCarree(), cmap = 'BuPu')
cbar= plt.colorbar(cs)
cbar.ax.set_ylabel(r"$Rainfall-(mm/day)$",rotation =270, labelpad=20, fontsize=14)
plt.show()

关于我如何做到这一点有什么建议吗? 谢谢你。

只需要调整对 add_subplot:

的调用
height = width/1.666

fig = plt.figure(figsize=(width, height))
ax = fig.add_subplot(1, 2, 1, projection=ccrs.PlateCarree())
ax.coastlines()
ax.gridlines()
ax.set_extent([66, 96, 4, 33])

ax.add_feature(cfeature.BORDERS)

ax.plot(77.2, 28.6, 'ro', markersize=7, transform=ccrs.Geodetic())
ax.text(77.2, 28.6, '   New Delhi', transform=ccrs.Geodetic())  
ax.plot(72.87, 19.07, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(72.87, 19.07, '   Mumbai', transform=ccrs.Geodetic()) 
ax.plot(77.59, 12.97, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(77.59, 12.97, '   Bangalore', transform=ccrs.Geodetic())  

cs = ax.contourf(lonind, latind, tind1988, transform=ccrs.PlateCarree(), cmap='BuPu')
cbar = plt.colorbar(cs)
cbar.ax.set_ylabel(r"$Rainfall-(mm/day)$", rotation=270, labelpad=20, fontsize=14)

ax = fig.add_subplot(1, 2, 2, projection=ccrs.PlateCarree())
ax.coastlines()
ax.gridlines()
ax.set_extent([66, 96, 4, 33])

ax.add_feature(cfeature.BORDERS)

ax.plot(77.2, 28.6, 'ro', markersize=7, transform=ccrs.Geodetic())
ax.text(77.2, 28.6, '   New Delhi', transform=ccrs.Geodetic())  
ax.plot(72.87, 19.07, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(72.87, 19.07, '   Mumbai', transform=ccrs.Geodetic()) 
ax.plot(77.59, 12.97, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(77.59, 12.97, '   Bangalore', transform=ccrs.Geodetic()) 

cs = ax.contourf(lonind, latind, tind2018, transform=ccrs.PlateCarree(), cmap = 'BuPu')
cbar = plt.colorbar(cs)
cbar.ax.set_ylabel(r"$Rainfall-(mm/day)$", rotation=270, labelpad=20, fontsize=14)

plt.show()

另请参阅 matplotlib 文档中的 this example