Skip to content
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

[Bug]: inset_axes colorbar + tight_layout raises AttributeError #22576

Closed
janosh opened this issue Mar 1, 2022 · 2 comments · Fixed by #22611
Closed

[Bug]: inset_axes colorbar + tight_layout raises AttributeError #22576

janosh opened this issue Mar 1, 2022 · 2 comments · Fixed by #22611

Comments

@janosh
Copy link

janosh commented Mar 1, 2022

Bug summary

I think #21749 wasn't fully fixed. mpl_toolkits.axes_grid1.inset_locator.inset_axes still appears to be affected. This still throws in v3.5.1:

Code for reproduction

import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes


matplotlib.__version__
# > '3.5.1'

fig, ax = plt.subplots(1, 1)
pts = ax.scatter([0, 1], [0, 1], c=[1, 5])

cax = inset_axes(ax, width="3%", height="70%")
plt.colorbar(pts, cax=cax)

plt.tight_layout()

Actual outcome

AttributeError: 'AnchoredSizeLocator' object has no attribute 'get_subplotspec'

Expected outcome

No error

Additional information

No response

Operating system

No response

Matplotlib Version

3.5.1

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.10.2

Jupyter version

No response

Installation

pip

@janosh janosh changed the title [Bug]: [Bug]: inset_axes colorbar + tight_layout raises AttributeError Mar 1, 2022
@QuLogic
Copy link
Member

QuLogic commented Mar 5, 2022

This bug is specific to the toolkit inset Axes. Using a standard inset Axes does work:

import matplotlib.pyplot as plt


fig, ax = plt.subplots(1, 1)
pts = ax.scatter([0, 1], [0, 1], c=[1, 5])
  
cax = ax.inset_axes([0.9, 0.15, 0.03, 0.7])
plt.colorbar(pts, cax=cax)
  
plt.tight_layout()
  
plt.show()

@QuLogic QuLogic added this to the v3.5.2 milestone Mar 5, 2022
@jklymak
Copy link
Member

jklymak commented Mar 5, 2022

Agreed but there is something wrong in the logic detecting if the axes is a subplot spec or not.

Sorry for my temporary absence but I am away from strong enough internet to interact heavily with GitHub.

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