Skip to main content
 首页 » 编程设计

python之AxesGrid 与 imshow : do plots have to have the same extent

2025年05月04日9qq78292959

我正在使用 AxesGrid 类绘制如下图:AxesGrid with imshow and contour

代码基本上是这样的:

      grid = AxesGrid(fig, 
                111, 
                nrows_ncols = (2,2), 
                axes_pad = 0.50, 
                label_mode = "all", 
                cbar_location='right', 
                cbar_mode='single', 
                cbar_pad =0.3, 
                cbar_size='5%' 
                ) 

然后对于 4 个面板中的每一个,我都这样调用 imshow 和 contour :

       # some definitions etc. 
 
 
        im1 = grid[0].imshow(np.transpose(De[i1:i2,j1:j2]), 
           aspect='equal', 
           vmin=vmin, vmax = vmax, 
           origin='lower', 
           extent=extent) 
 
 
    # some other stuff [...] 
 
 
        grid[0].contour(np.transpose(F[i1:i2,j1:j2]),levels=levls, 
                extent=extent,colors='k',cmap=None) 
 
    # and so on for the 3 other panels 

唯一的区别是现在,我希望图像对 extent 关键字具有不同的值。 假设我希望右上角图像的范围为 (31.5,35.5,11,14),右下角面板的范围为 (29.5, 33.5, 11, 14),我得到这个:

new plot

似乎 matplotlib 调整了轴。有没有一种方法可以指定我想要的范围,并且我的数据和 ax 之间没有空白区域?

请您参考如下方法:

添加参数:

share_x=False 

致您的网格一代。然后您可以单独设置每个绘图的 xlim。