Repository navigation
Closed
Milestone
Description
Bug report
** plt.fignum_exists() returns True after figure is closed**
Code snippet below closes figure after creating FigureCanvasAgg, and it works with matplotlib-3.2.1 but fails with matplotlib-3.3.0
Code for reproduction
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
figure = plt.figure()
plt.axis('scaled')
plt.tight_layout()
matplotlib.backends.backend_agg.FigureCanvasAgg(figure)
plt.close(figure)
print("Matplotlib version:", matplotlib.__version__)
assert plt.fignum_exists(figure.number) == FalseActual outcome
Matplotlib version: 3.3.0
Traceback (most recent call last):
File "figure_exists.py", line 11, in <module>
assert plt.fignum_exists(figure.number) == False
AssertionError
Expected outcome
No assertion, which is easy to reproduce if one to downgrade to matplotlib-3.2.1:
pip3 install matplotlib==3.2.1 --user; python figure_exists.py
Collecting matplotlib==3.2.1
Using cached https://files.pythonhosted.org/packages/b2/c2/71fcf957710f3ba1f09088b35776a799ba7dd95f7c2b195ec800933b276b/matplotlib-3.2.1-cp37-cp37m-manylinux1_x86_64.whl
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/lib/python3.7/site-packages (from matplotlib==3.2.1) (2.4.0)
Requirement already satisfied: numpy>=1.11 in /usr/local/lib64/python3.7/site-packages (from matplotlib==3.2.1) (1.18.4)
Requirement already satisfied: python-dateutil>=2.1 in /usr/lib/python3.7/site-packages (from matplotlib==3.2.1) (2.8.0)
Requirement already satisfied: cycler>=0.10 in /usr/lib/python3.7/site-packages (from matplotlib==3.2.1) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/lib64/python3.7/site-packages (from matplotlib==3.2.1) (1.1.0)
Requirement already satisfied: six>=1.5 in /usr/lib/python3.7/site-packages (from python-dateutil>=2.1->matplotlib==3.2.1) (1.12.0)
Requirement already satisfied: setuptools in /usr/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib==3.2.1) (40.8.0)
Installing collected packages: matplotlib
Found existing installation: matplotlib 3.3.0
Uninstalling matplotlib-3.3.0:
Successfully uninstalled matplotlib-3.3.0
Successfully installed matplotlib-3.2.1
Matplotlib version: 3.2.1
Matplotlib version
- Operating system: Fedora Core 30
- Matplotlib version: 3.3.0 (installed via pip as
pip3 install matplotlib==3.3.0 --user) - Matplotlib backend (
print(matplotlib.get_backend())): - Python version: 3.7.0
- Jupyter version (if applicable):
- Other libraries:
Metadata
Metadata
Assignees
Labels
No labels
Activity
Skip part of test_figure[_list] if Matplotlib-3.3.0 is installed (#42500
dopplershift commentedon Aug 4, 2020
Well, I can reproduce. The problem is the line:
This resets the canvas of
figure; this also leaves things in a state wherefigure.canvasisNone, which then throws off the machinery for closing the figure because the currently set manager doesn't match the manager under the key1, so it doesn't do anything. What I'm unclear on is what, if anything should be happening here.QuLogic commentedon Aug 4, 2020
So the question is, why are you doing this:
and what do you expect it to do?
tacaswell commentedon Aug 5, 2020
This goes back to 7fcf123 where we changed from searching the managers we know about for the figure to asking the figure who its manager is. At the time @QuLogic raised slight concerns (https://github.com/matplotlib/matplotlib/pull/13581/files#r261907128).
I think what is happening is that when we set the new canvas, it does not have a manager, but we still have a manager in the global state that is disconnected from its original manager.
Go back to checking figures for their manager in destroy.
Go back to checking figures for their manager in destroy.
[-]Figure can not be closed if it has associated Agg canvas[/-][+]Figure cannot be closed if it has associated Agg canvas[/+]