在Matplotlib中并排绘制轮廓图?

问题描述 投票:0回答:1

我有两个印度不同年份的降水等值线图,我希望能够以相同的功能,最好是并排打印。我不确定该怎么做。

地图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()

关于如何执行此操作的任何建议?谢谢。

python python-3.x matplotlib cartopy
1个回答
1
投票

所需要做的就是将呼叫调整为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

© www.soinside.com 2019 - 2024. All rights reserved.