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

legend.get_window_extent() fails #21285

Closed
durack1 opened this issue Oct 5, 2021 · 2 comments
Closed

legend.get_window_extent() fails #21285

durack1 opened this issue Oct 5, 2021 · 2 comments

Comments

@durack1
Copy link

durack1 commented Oct 5, 2021

Bug summary

It seems a bug has crept in with points_to_pixels not available as a function called by get_window_extent

Code for reproduction

(Pdb) leg2 = plt.legend(loc='upper left', ncol=2, fontsize=8)
(Pdb) leg2.get_window_extent()
*** AttributeError: 'NoneType' object has no attribute 'points_to_pixels'
(Pdb) print(matplotlib.__version__)
3.4.2
(Pdb) print(matplotlib.get_backend())
MacOSX
(Pdb) import sys; print(sys.version_info)
sys.version_info(major=3, minor=9, micro=6, releaselevel='final', serial=0)
$ jupyter --version
jupyter core     : 4.7.1
jupyter-notebook : 6.4.0
qtconsole        : 5.1.1
ipython          : 7.25.0
ipykernel        : 6.0.1
jupyter client   : 6.1.12
jupyter lab      : not installed
nbconvert        : 6.1.0
ipywidgets       : 7.6.3
nbformat         : 5.1.3
traitlets        : 5.0.5

Actual outcome

Error, as above

Expected outcome

I expected to get coords

Operating system

MacOS 11.6

Matplotlib Version

3.4.2

Matplotlib Backend

MacOSX

Python version

3.9.6

Jupyter version

core 4.7.1; notebook 6.4.0

Other libraries

No response

Installation

conda

Conda channel

conda-forge

@jklymak
Copy link
Member

jklymak commented Oct 6, 2021

get_window_extent has a renderer argument. Its optional for some methods and required by others. If it is set to None it uses the cached renderer, but that requires a draw to have been executed first. In this case you have no draw, so the call fails.

I'm skeptical this ever worked. If so, can you tell us what version? Maybe the renderer cache has changed in some way.

In the meantime, it is safest to call leg2.get_window_extent(fig.canvas.get_renderer()).

@tacaswell tacaswell added this to the v3.6.0 milestone Dec 1, 2021
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Aug 24, 2022
@QuLogic
Copy link
Member

QuLogic commented Jan 25, 2023

I believe this was fixed by #22745.

@QuLogic QuLogic closed this as completed Jan 25, 2023
@QuLogic QuLogic modified the milestones: v3.7.0, v3.6.0 Jan 25, 2023
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