具有不同区域底图的子图显示大小不同

Subplots with Basemap of different regions appears different size

绘制不同区域的底图时,我得到的子图大小不等。如何获得相同大小的子图。 代码看起来像

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
#########################
fig = plt.figure(figsize=(15, 8))
ax1=plt.subplot(1, 2, 1)
m = Basemap(projection='cyl', resolution='l',
            llcrnrlat=0, llcrnrlon=-120,
            urcrnrlat=35, urcrnrlon=-60)
parallels = np.arange(-90.,90,10.)
m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
meridians = np.arange(0.,360.,10.)
m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
m.drawcoastlines(color='black', linewidth=0.5)
#--------------------------------------------------------------------
ax2=plt.subplot(1, 2, 2)
m = Basemap(projection='cyl', resolution='l',
            llcrnrlat=0, llcrnrlon=40,
            urcrnrlat=35, urcrnrlon=90)
parallels = np.arange(-90.,90,10.)
m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
meridians = np.arange(0.,360.,10.)
m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
m.drawcoastlines(color='black', linewidth=0.5)
plt.show()

您可以使用 matplotlib.gridspec 来获得操纵子图的各个高度的能力。这是一个演示代码。

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import matplotlib.gridspec as gridspec

# set proper figsize here, large value of width
fig = plt.figure(figsize=(14, 4))

# width_ratios is obtained by trial and error
gs = gridspec.GridSpec(1, 2, width_ratios=[1.25, 1])
ax1 = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])

# add ax=ax1 to make use of `ax1`
m = Basemap(projection='cyl', resolution='l',
            llcrnrlat=0, llcrnrlon=-120,
            urcrnrlat=35, urcrnrlon=-60, ax=ax1)
parallels = np.arange(-90.,90,10.)
m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
meridians = np.arange(0.,360.,10.)
m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
m.drawcoastlines(color='black', linewidth=0.5)

#--------------------------------------------------------------------
# add ax=ax2 to make use of `ax2`
m = Basemap(projection='cyl', resolution='l',
            llcrnrlat=0, llcrnrlon=40,
            urcrnrlat=35, urcrnrlon=90, ax=ax2)
parallels = np.arange(-90.,90,10.)
m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
meridians = np.arange(0.,360.,10.)
m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
m.drawcoastlines(color='black', linewidth=0.5)
plt.show()