10000 colorbar.make_axes doesn't anchor in constrained_layout · Issue #14638 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
colorbar.make_axes doesn't anchor in constrained_layout #14638
Closed
@nspies-celsiustx

Description

@nspies-celsiustx

Bug report

Bug summary

There doesn't appear a way to move colorbars up and down when using colorbar.make_axes() in constrained_layout=True mode. The anchor argument appears to be functionally ignored. (Note that location specifies left/right/top/bottom, whereas anchor should move the colorbar within the specified location, eg if the default location of right is chosen, anchor allows moving the colorbar to the top or bottom.)

This appears to be an incomplete implementation of the constrained_layout.layoutcolorbargridspec function, called from here:

https://github.com/matplotlib/matplotlib/blob/c8b92926a880163394e3bd7f56220b65df71646c/lib/matplotlib/_constrained_layout.py

Please let me know if I'm missing something or if there's a workaround.

Code for reproduction

fig, ax = plt.subplots(constrained_layout=True)
ax.scatter(np.arange(100), np.arange(100), c=np.arange(100))
cax, _ = matplotlib.colorbar.make_axes(ax, shrink=0.5, anchor=(0.0, 1.0))
cbar = matplotlib.colorbar.ColorbarBase(cax)

Actual outcome

With constrained_layout=True:
image

Expected outcome

With constrained_layout=True, the anchor argument is honored:
image

(Note that the colorbar has moved to the top, as expected given the anchor=(0, 1.0).)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0