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

标签 python matplotlib

我正在使用 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。

关于python - AxesGrid 与 imshow : do plots have to have the same extent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14244593/

相关文章:

python - sklearn 用户的 R 插入符号

python - PyGTK:制作一个行为类似于 OpenOffice 的 TextView

python - 如何在 Django 网页中嵌入 matplotlib 图形?

python - 两种不同的可视化结果

pandas - 具有两个 Y 轴和公共(public) X 轴的 Matplotlib 条形图

python - 使用 shapely descartes 和 matplotlib 绘制断开连接的实体

python - 如何获取任何 python 方法的参数?

python - 无法弄清楚嵌套的 for 循环部分以及它在这段代码中是如何工作的

Python:我可以在导入函数中设置 pdb.set_trace()

python - 使用 matplotlib 绘制数组列表