Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib Pyplot ImageGrid图形问题_Python_Matplotlib - Fatal编程技术网

Python Matplotlib Pyplot ImageGrid图形问题

Python Matplotlib Pyplot ImageGrid图形问题,python,matplotlib,Python,Matplotlib,我遇到了AXES_GRID1()的问题。特别是在ImageGrid()的使用中 以下代码准备并显示与预期完全相同的图形: import matplotlib.pyplot as plt # from mpl_toolkits.axes_grid1 import AxesGrid from mpl_toolkits.axes_grid1 import ImageGrid import numpy as np fig = plt.figure(figsize=(15, 15)) grid = I

我遇到了AXES_GRID1()的问题。特别是在ImageGrid()的使用中

以下代码准备并显示与预期完全相同的图形:

import matplotlib.pyplot as plt
# from mpl_toolkits.axes_grid1 import AxesGrid
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np

fig = plt.figure(figsize=(15, 15))

grid = ImageGrid(fig, 111,
                nrows_ncols=(3, 4), 
                axes_pad=0.5,
                cbar_mode='single',
                cbar_location='right',
                cbar_pad=0.5,
                direction='row',
                )
plt.tight_layout()
plt.show()

但一旦我将我的数字添加到相关轴上,如下所示:

import matplotlib.pyplot as plt
# from mpl_toolkits.axes_grid1 import AxesGrid
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np

fig = plt.figure(figsize=(15, 15))

grid = ImageGrid(fig, 111,
                nrows_ncols=(3, 4), 
                axes_pad=0.5,
                cbar_mode='single',
                cbar_location='right',
                cbar_pad=0.5,
                direction='row',
                )
rc = 0
for season in ('MAM', 'JJA', 'SON'):
    im = dat_fluo_ref.sel(time=select_season(dat_fluo_ref['time.season'], season)).groupby('time.hour').mean('time').radiance.plot.pcolormesh(
        ax=grid[rc + 0], vmin=0, vmax=0.5, cmap='Spectral_r', add_colorbar=False,)

    im = dat_fluo_inc.sel(time=select_season(dat_fluo_inc['time.season'], season)).groupby('time.hour').mean('time').radiance.plot.pcolormesh(
        ax=grid[rc + 1], vmin=0, vmax=0.5, cmap='Spectral_r', add_colorbar=False,)

    im = dat_full_ref.sel(time=select_season(dat_full_ref['time.season'], season)).groupby('time.hour').mean('time').radiance.plot.pcolormesh(
        ax=grid[rc + 2], vmin=0, vmax=0.5, cmap='Spectral_r', add_colorbar=False,)

    im = dat_full_inc.sel(time=select_season(dat_full_inc['time.season'], season)).groupby('time.hour').mean('time').radiance.plot.pcolormesh(
        ax=grid[rc + 3], vmin=0, vmax=0.5, cmap='Spectral_r', add_colorbar=False)
    rc += 4
cbar = grid.cbar_axes[0].colorbar(im)
plt.tight_layout()
plt.show()
然后,生成的图形(请参见)看起来不再像预览(请参见)

这可能是传递给ImageGrid的参数的问题。


谢谢你的帮助

ImageGrid
正在尝试为像素保持方形。如果您的列比行多,那么这可能不是您想要实现的目标。构建ImageGrid时,尝试传递
aspect=False

比较:

from mpl_toolkits.axes_grid1 import ImageGrid

fig = plt.figure()
grid = ImageGrid(fig, 111,
                 nrows_ncols=(3, 4),
                 axes_pad=0.5,
                 cbar_mode='single',
                 cbar_location='right',
                 cbar_pad=0.5,
                 direction='row',
                 aspect=False
                )
for ax in grid.axes_all:
    ax.pcolormesh(np.random.random(size=(5,20)))


ImageGrid
正在尝试为像素保持方形。如果您的列比行多,那么这可能不是您想要实现的目标。构建ImageGrid时,尝试传递
aspect=False

比较:

from mpl_toolkits.axes_grid1 import ImageGrid

fig = plt.figure()
grid = ImageGrid(fig, 111,
                 nrows_ncols=(3, 4),
                 axes_pad=0.5,
                 cbar_mode='single',
                 cbar_location='right',
                 cbar_pad=0.5,
                 direction='row',
                 aspect=False
                )
for ax in grid.axes_all:
    ax.pcolormesh(np.random.random(size=(5,20)))


感谢您的努力@Diziet Asahi,成功了。尽管他们写到默认值为“False”,但这仅适用于AxisGrid,而wheras ImageGrid的默认值为“true”。谢谢不客气。如果该解决方案解决了问题,请考虑使用左边的复选标记来关闭答案关闭主题。谢谢你的努力,Diziet Asahi成功了。尽管他们写到默认值为“False”,但这仅适用于AxisGrid,而wheras ImageGrid的默认值为“true”。谢谢不客气。如果该解决方案解决了问题,请考虑使用左边的复选标记来关闭答案关闭主题。看见