Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
When plotting a 4x4 ImageGrid and using a discretised normalisation the colourbar at the bottom of a column does not use the entire available width if theextend
argument in the normalisation is set to something other than'neither'
. Below I have included example plots of what this looks like. As can be seen, only when setting extend to'neither'
in the normalisation does the colourbar use the entire space on the x-axis from 0 to 10. The associated colourbar label also ends up not being centred (except whenextend
is set to'both'
).
Code for reproduction
importmatplotlib.pyplotaspltimportmatplotlib.colorsasmcolorsimportnumpyasnpfrommpl_toolkits.axes_grid1importImageGriddefplot_grid(extend):im=np.arange(100).reshape((10,10))fig=plt.figure()grid=ImageGrid(fig,111,nrows_ncols=(2,2),axes_pad=0.2,cbar_mode='edge',cbar_location='bottom',cbar_pad=0.3,direction='column')bounds= [0,2,4,6,8,10]norm=mcolors.BoundaryNorm(boundaries=bounds,ncolors=256,extend=extend)c=grid[0].pcolormesh(im,norm=norm)cbar=grid[0].cax.colorbar(c)cbar.set_label('foo')c=grid[1].pcolormesh(im,norm=norm)cbar=grid[1].cax.colorbar(c)cbar.set_label('foo')c=grid[2].pcolormesh(im)cbar=grid[2].cax.colorbar(c)cbar.set_label('foo')c=grid[3].pcolormesh(im)cbar=grid[3].cax.colorbar(c)cbar.set_label('foo')fig.suptitle(f'extend=\'{extend}\'')fig.savefig(f'{extend}.png')plot_grid('neither')plot_grid('min')plot_grid('max')plot_grid('both')
Actual outcome
Settingextend
equal to'min'
,'max'
, or'both'
shortens the colourbar causing it to not use all available horizontal space, and the colourbar label is not centred whenextend
is set to'min'
or'max'
.
Expected outcome
Colourbars should always use the full width available, and the associated label should be centred.
Additional information
You should add an option foruv
under how did you installmatplotlib
, because that is how I installed it.
Operating system
Ubuntu 22.04
Matplotlib Version
3.10.1
Matplotlib Backend
qtagg
Python version
3.12.8
Jupyter version
No response
Installation
None