Skip to content

Closing figures is done by number #15203

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
vnmabus opened this issue Sep 6, 2019 · 4 comments · Fixed by #16819
Closed

Closing figures is done by number #15203

vnmabus opened this issue Sep 6, 2019 · 4 comments · Fixed by #16819
Milestone

Comments

@vnmabus
Copy link
Contributor

vnmabus commented Sep 6, 2019

Closing figures is done by number

Currently, closing a figure is done using the num attribute in the manager. This can cause problems if there are figures not managed by pyplot, as the number could be the same as a
pyplot-managed figure.

As there are efforts to reduce the dependency on pyplot, such as #14024, this should be changed for those to work well. Alternatively, a way to create a manager which selects an appropiate number could work.

Code for reproduction

import matplotlib.pyplot as plt 

# Figure managed by pyplot 
fig1 = plt.figure() 
 
# Figure not managed by pyplot, but using the same backend 
fig2 = fig = plt.new_figure_manager(1).canvas.figure 

fig1.show() 
fig2.show()

Actual outcome

Closing one figure closes both.

Expected outcome

Closing one figure leaves the other open.

Matplotlib version

  • Operating system: All
  • Matplotlib version: 3.0.3
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: All
@tacaswell tacaswell added this to the v3.3.0 milestone Sep 6, 2019
@tacaswell
Copy link
Member

The linkage is only one way, if you close the un-managed figure it closes the managed figure, but not the other way around.

Alternatively, a way to create a manager which selects an appropriate number could work.

How do you do that without managing all of the figures?

As a work around, you can do:

fig2.canvas.manager.num = str(uuid.uuid4)

which will de-couple everything.


Somewhat annoyingly, the only place that looks like it actually requires an integer is formatting the initial widow title.

@anntzer
Copy link
Contributor

anntzer commented Sep 7, 2019

Somewhat annoyingly, the only place that looks like it actually requires an integer is formatting the initial widow title.

Actually there's also Figure.__setstate__ which assumes it can assign a number to an unpickled figure with max(plt.get_fignums()) + 1.

@tacaswell
Copy link
Member

global state + pickling!

@jklymak
Copy link
Member

jklymak commented Sep 8, 2019

I'm not up on how this all works, but it seems that pyplot should be keeping track of figure handles, not figure numbers or title strings?

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