簡體   English   中英

在 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 文檔中的此示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM