【问题标题】:Imshow subplots share colorbar using AxesGrid. How to plot a grid and set number of ticksImshow 子图使用 AxesGrid 共享颜色条。如何绘制网格并设置刻度数
【发布时间】:2014-04-03 08:21:51
【问题描述】:

我的程序使用相同的颜色条绘制三个子图。代码如下:

fig=pl.figure()
grid = AxesGrid(fig, 111,nrows_ncols=(3,1),
            axes_pad = 0.2,
            share_all=True,
            label_mode = "L",
            cbar_location = "right",
            cbar_mode="single",
            cbar_size='1%'
            )

im = grid[0].imshow(np.random.random((10,50)))  
grid.cbar_axes[0].colorbar(im)
im = grid[1].imshow(np.random.random((10,50)))
im = grid[2].imshow(np.random.random((10,50)))
pl.show()

这提供了以下图片:

不,我想先设置滴答数。例如。 y 轴上有 3 个刻度,x 轴上有 10 个刻度。此外,我想在图片中绘制一个网格。但是我的正常编码只有在我不使用 AxisGrid 时才有效:

fig=pl.figure()
im = imshow(np.random.random((10,50)))
pl.locator_params(axis='x',nbins=20)
pl.locator_params(axis='y',nbins=3)
pl.grid()
pl.show()

如何将网格绘制到子图中并更改刻度数?

【问题讨论】:

    标签: matplotlib grid subplot imshow


    【解决方案1】:

    试试这个:

    im = grid[0].imshow(np.random.random((10,50)))  
    ax = im.get_axes( )
    ax.grid( 'on' )
    ax.locator_params(axis='x',nbins=20)
    ax.locator_params(axis='y',nbins=3)
    

    【讨论】:

      猜你喜欢
      • 2019-03-19
      • 2023-04-09
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 1970-01-01
      相关资源
      最近更新 更多