Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9285087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:04:25+00:00 2026-06-18T19:04:25+00:00

In Matplotlib: I can write matplotlib.pyplot.cla() as axes.clear() , where axes is an matplotlib.axes.Axes

  • 0

In Matplotlib:

  • I can write matplotlib.pyplot.cla() as axes.clear(), where axes is an matplotlib.axes.Axes object.
  • I can write matplotlib.pyplot.clf() as fig.clear(), where fig is a matplotlib.figure.Figure object.

Then there is matplotlib.pyplot.close(). This closes a window. Does this window correspond to any class? Is there a x.close() that is equivalent to matplotlib.pyplot.close() but in a more object oriented style?

The source code for matplotlib.pyplot.close() for my version is as follows:

if len(args)==0:
    figManager = _pylab_helpers.Gcf.get_active()
    if figManager is None: return
    else:
        _pylab_helpers.Gcf.destroy(figManager.num)
elif len(args)==1:
    arg = args[0]
    if arg=='all':
        _pylab_helpers.Gcf.destroy_all()
    elif isinstance(arg, int):
        _pylab_helpers.Gcf.destroy(arg)
    elif is_string_like(arg):
        allLabels = get_figlabels()
        if arg in allLabels:
            num = get_fignums()[allLabels.index(arg)]
            _pylab_helpers.Gcf.destroy(num)
    elif isinstance(arg, Figure):
        _pylab_helpers.Gcf.destroy_fig(arg)
    else:
        raise TypeError('Unrecognized argument type %s to close'%type(arg))
else:
    raise TypeError('close takes 0 or 1 arguments')

So, it appears to be based on the staticmethod
matplotlib._pylab_helpers.Gcf.destroy which does a variety of things I don’t quite follow, noting that In the interactive backends, this is bound to the window “destroy” and “delete” events. But I’m not sure how figures and windows are related.

Perhaps I’m wasting my time even thinking about this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:04:28+00:00Added an answer on June 18, 2026 at 7:04 pm

    Gcf is a global singleton object that keeps a list of the figures you have opened with plt.figure.

    It is essentially a dictionary with some fancy code around it to keep things consistent and keep track of the active figure, ect. The class that is used as a layer between Figure (which is what is returned by plt.figure) and the GUI layer is FigureManagerBase (and it’s per-toolkit sub-classes) which is defined in backend_bases.py.

    Which sub-class you are using is determined by which backend you are using. These sub-classes deal with things like making sure the figure gets deleted when you click the ‘x’ button, and the system level gui call-backs.

    FigureManagers have a destroy method which triggers their internal tear down. In principle, if you have a Figure object and want to destroy it by hand, you just need to get a hold of the manager. A reference to it isn’t stored in the Figure object, but is stored in the Canvas object so you can destroy a window via

    fig.canvas.manager.destroy()
    

    which will tear the figure down, however if you do this, it might not properly clean up Gcf (which will retains a reference to the figure manager) which will make future figures made with pyplot have unexpected numbers (it won’t go back to one), gca will not work as exected, ect (this is the case with Qt4).

    If you are going to use pyplot at all (and be sure it will always work on every backend), then you either need to

    1. directly talk to Gcf (it’s in _pyplot_helpers.py and really isn’t too complicated once you see what it is trying to do
    2. reach and talk to the GUI directly (see the code in lib/matplotlib/tests/test_backend_qt4.py for how to do with with qt4, but this is going to be very toolkit dependent)
    3. plt.close(fig.number)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In matplotlib , I can set the axis scaling using either pyplot.xscale() or Axes.set_xscale()
import sys import matplotlib import matplotlib.pyplot as plt print matplotlib.__version__, matplotlib.get_backend() def hit(event): sys.stderr.write('hit\n')
I've been playing around with Matplotlib and I can't figure out how to change
Can you draw the grid lines in a plot with parasitic axes in matplotlib?
I'm generating a bar-chart with matplotlib. It all works well but I can't figure
I've got a Matplotlib graph with two y axes, created like: ax1 = fig.add_subplot(111)
How can I create some gradient color in matplotlib and then set the parameter
I'm working on PyGTK application, that can generate graphs. This achieved by matplotlib. How
For the life of me, I can not get matplotlib to display graphs in
With, say, 3 rows of subplots in matplotlib, xlabels of one row can overlap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.