Matplotlib 如何在共享颜色条的等高线图子图中共享X轴

Matplotlib 如何在共享颜色条的等高线图子图中共享X轴,matplotlib,subplot,colorbar,cartopy,Matplotlib,Subplot,Colorbar,Cartopy,我试着制作3个子图,它们共享一个颜色条和xaxis,正如中的spinup所解释的 在子地块中使用地图(带海岸线),似乎不支持sharex。 但是,有没有一种方法可以应用共享轴 import cartopy.crs as ccrs from cartopy.mpl.geoaxes import GeoAxes from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter import matplotlib.pyplot

我试着制作3个子图,它们共享一个颜色条和xaxis,正如中的spinup所解释的

在子地块中使用地图(带海岸线),似乎不支持sharex。 但是,有没有一种方法可以应用共享轴

import cartopy.crs as ccrs
from cartopy.mpl.geoaxes import GeoAxes
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
import numpy as np

def sample_data_3d(shape):
    """Returns `lons`, `lats`, `times` and fake `data`"""
    ntimes, nlats, nlons = shape
    lats = np.linspace(-np.pi / 2, np.pi / 2, nlats)
    lons = np.linspace(0, 2 * np.pi, nlons)
    lons, lats = np.meshgrid(lons, lats)
    wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)
    mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)

    lats = np.rad2deg(lats)
    lons = np.rad2deg(lons)
    data = wave + mean

    times = np.linspace(-1, 1, ntimes)
    new_shape = data.shape + (ntimes, )
    data = np.rollaxis(data.repeat(ntimes).reshape(new_shape), -1)
    data *= times[:, np.newaxis, np.newaxis]

    return lons, lats, times, data

def main():
    projection = ccrs.PlateCarree()
    axes_class = (GeoAxes,
                  dict(map_projection=projection))

    lons, lats, times, data = sample_data_3d((6, 73, 145))

    fig = plt.figure()
    axgr = AxesGrid(fig, 111, axes_class=axes_class,
                    nrows_ncols=(3, 1),
                    axes_pad=0.6,
                    share_all=True, #doesn't change anything
                    cbar_location='bottom',
                    cbar_mode='single',
                    cbar_pad=0.2,
                    cbar_size='3%',
                    label_mode='')  # note the empty label_mode

    for i, ax in enumerate(axgr):
        ax.coastlines()
        ax.add_feature(cartopy.feature.LAND, zorder=100,              
                       edgecolor='k',facecolor='w')

        ax.set_xticks(np.linspace(-180, 180, 5), crs=projection)
        ax.set_yticks(np.linspace(-90, 90, 5), crs=projection)

    p = ax.contourf(lons, lats, data[i, ...],
                    transform=projection,
                    cmap='RdBu')

    axgr.cbar_axes[0].colorbar(p)

    plt.show()

轴是共享的。你能详细说明具体的问题是什么吗?我只想在底部标记子地块的轴
ax.tick_params(labelbottom=False)
?正好相反,比如:子地块1:x ticks不带ticklabels子地块2:x ticks不带ticklabels子地块3:x ticks带ticklabels有人知道吗?