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

[ENH]: Ignore ticklabels in colorbar constrained-positioning #26014

Copy link
Copy link
Open
@anntzer

Description

@anntzer
Issue body actions

Problem

Sometimes, trying to stick a colorbar next to its "parent" axes by using pad=0 will "fail" if the axes has a ticklabel that extends beyond the axes' spines:

from pylab import *
fig = figure(layout="constrained", figsize=(8, 4))
axs = fig.subplots(1, 2)
for i, ax in enumerate(axs):
    im = ax.imshow(np.arange(9).reshape((3, 3)), aspect="auto")
    fig.colorbar(im, pad=0, ticks=[])
axs[0].set(xlim=(-.5, 2.5), xticks=[0, 1, 2], yticks=[])
axs[1].set(xlim=(0, 3), xticks=[0, 1, 2, 3], yticks=[])
show()

test
see the small extra spacing between the left axes and the left colorbar, not present on the right.

Proposed solution

I'm not sure this can reliably be handled automatically (the desirable behavior also depends on whether the colorbar's vertical extent goes goes beyond the axes' vertical extent, which will depend on how exactly the colorbar is positioned, whether the parent axes uses fixed aspect (here I disabled fixed aspect ratio on imshow).

But it would be nice if one could at least tweak that manually with something like axs[1].xaxis.set_in_layout(False). Bonus points if one can do set_in_layout("y"), i.e. take the xaxis in account but only for its vertical extent (we don't want the labels to fall off below the figure), not for its horizontal extent.

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.