Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: colorbar ignores keyword panchor=False #23157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rcomer opened this issue May 27, 2022 · 3 comments · Fixed by #23203
Closed

[Bug]: colorbar ignores keyword panchor=False #23157

rcomer opened this issue May 27, 2022 · 3 comments · Fixed by #23203

Comments

@rcomer
Copy link
Member

rcomer commented May 27, 2022

Bug summary

colorbar seems to ignore the keyword setting panchor=False

Code for reproduction

import matplotlib
print('mpl version:', matplotlib.__version__)
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(5, 8))
ax = fig.add_subplot(1, 1, 1, aspect=0.5, anchor="N")

a = np.arange(12)[:,np.newaxis] * np.ones(8)
levels = np.arange(1.5, 10, 2)

plt.contourf(a, cmap='RdYlBu', levels=levels, extend='both')
print('anchor before colorbar:', ax.get_anchor())
plt.colorbar(orientation='horizontal', panchor=False)
print('anchor after colorbar:', ax.get_anchor())

Actual outcome

mpl version: 3.6.0.dev2341+g3df958c760
anchor before colorbar: N
anchor after colorbar: (0.5, 0.0)

Expected outcome

My reading of the docs is that the axes anchor should still be "N" after I add the colorbar. Though given #18752, it's possible I have misunderstood!

panchor(float, float), or False, optional

The anchor point of the colorbar parent axes. If False, the parent axes' anchor will be unchanged. Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.

Additional information

No response

Operating system

No response

Matplotlib Version

main branch (3.6.0.dev2341+g3df958c760), 3.5.2 and some older (3.3+) versions.

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

No response

@rcomer
Copy link
Member Author

rcomer commented May 27, 2022

I think maybe this is the problem line:

parent.set_anchor(loc_settings["panchor"])

and it should be handled the same as in make_axes

panchor = kwargs.pop('panchor', loc_settings['panchor'])

if panchor is not False:
ax.set_anchor(panchor)

@oscargus
Copy link
Member

This was recently changed in #22776 to fix a problem introduced in #20129

Maybe @QuLogic and @anntzer knows more about the details.

@anntzer
Copy link
Contributor

anntzer commented May 27, 2022

Actually the code prior to #20129 also didn't have the if loc_settings["panchor"] is not False: check, so I don't think my changes really matter here? Without having carefully checked, the proposed fix makes sense, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants