Skip to content

Figure cannot be closed if it has associated Agg canvas #18163

@malfet

Description

@malfet

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) == False

Actual 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy