Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Colourbars sometimes don't use all available width with ImageGrid #29809

Copy link
Copy link
Closed as not planned
@huaracheguarache

Description

@huaracheguarache
Issue body actions

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 the extend 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 when extend is set to 'both').

Image

Image

Image

Image

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np

from mpl_toolkits.axes_grid1 import ImageGrid


def plot_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

Setting extend 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 when extend 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 for uv under how did you install matplotlib, 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.