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

  • Home
  • SEARCH
  • 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 5842623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:02:31+00:00 2026-05-22T12:02:31+00:00

In matplotlib, I keep a reference on an axis. I want to open a

  • 0

In matplotlib, I keep a reference on an axis. I want to open a new figure if the window that contain the axis have been closed. The idea is to keep adding plots on the figure, until it is closed, then I open a new figure.
Note that the creation of new plots is triggered by an event in another figure.

If it can help you to understand what I am trying to do, here is the class:

class DetailedPlot(object):
    def __init__(self, figure):
        self.origin_figure = figure

        self.axis = None
        self.print_figure = None

        self.origin_figure.canvas.mpl_connect('button_press_event', self)


    def __call__(self, event):
        if event.xdata is None or event.ydata is None:
            return
        r = round(event.xdata - 0.025, 1)
        l = round(event.ydata - 0.025, 1)
        if self.axis is None or self.axis.belongs_to_a_closed_window():
            self.print_figure = plt.figure()
            self.axis = self.print_figure.add_subplot(111)
        plotting_fcn(self.axis, r, l)

My aim to to find a function such as belongs_to_a_closed_window

  • 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-05-22T12:02:31+00:00Added an answer on May 22, 2026 at 12:02 pm

    Why not just connect a callback to the "close_event"? You could either add a ax.has_been_closed flag to the axes object or your class itself. (There are probably even cleaner solutions than a “has_been_closed” flag, depending on exactly what you’re doing… The callback function can be anything.)

    import matplotlib.pyplot as plt
    
    def on_close(event):
        event.canvas.figure.axes[0].has_been_closed = True
        print 'Closed Figure'
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.has_been_closed = False
    ax.plot(range(10))
    
    fig.canvas.mpl_connect('close_event', on_close)
    
    plt.show()
    
    print ax.has_been_closed
    

    Edit: (Expanding on my comment below) If the OSX backend end doesn’t properly implement a close event, you could also do something like this:

    import matplotlib.pyplot as plt
    
    def has_been_closed(ax):
        fig = ax.figure.canvas.manager
        active_fig_managers = plt._pylab_helpers.Gcf.figs.values()
        return fig not in active_fig_managers
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(range(10))
    
    print has_been_closed(ax)
    
    plt.show()
    
    print has_been_closed(ax)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have two figures in matplotlib, with one plot per figure: import
I am playing with matplotlib - I have a bar chart, and I want
How to scale the y-axis with Matplotlib ? I don't want to change the
I am new to matplotlib and I am trying to figure out if I
I have a matplotlib figure inside of a wxmpl panel, and am trying to
Matplotlib has a function that writes text in figure coordinates (.figtext()) Is there a
I have a matplotlib figure on a canvas on a wxpython panel. My application
I have used Matplotlib to plot lines on a figure. Now I would now
I'm trying to install matplotlib on my mac setup. I find that setup.py has
I want to keep the width of the bars the same no matter the

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.