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 6618829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:53:14+00:00 2026-05-25T20:53:14+00:00

I am using matplotlib in interactive mode to show the user a plot that

  • 0

I am using matplotlib in interactive mode to show the user a plot that will help them enter a range of variables. They have the option of hitting “?” to show this plot, and the prompt for variables will then be repeated.

How do I know to not re-draw this plot if it’s still being displayed?

Superficially, I have this clunky (pseudo-ish) code:

answer = None
done_plot = False
while answer == None:
    answer = get_answer()
    if answer == '?':
        if done_plot:
            have_closed = True
            ##user's already requested a plot - has s/he closed it?
            ## some check here needed:
            have_closed = ?????

            if have_closed == False:
                print 'You already have the plot on display, will not re-draw'
                answer = None
                continue
        plt.ion()
        fig = plt.figure()
        ### plotting stuff
        done_plot = True
        answer = None
    else:
        ###have an answer from the user...

what can I use (in terms of plt.gca(), fig etc…) to determine if I need to re-plot? Is there a status somewhere I can check?

Many thanks,

David

  • 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-25T20:53:15+00:00Added an answer on May 25, 2026 at 8:53 pm

    In the same vein as unutbu’s answer, you can also check whether a given figure is still opened with

    import matplotlib.pyplot as plt
    
    if plt.fignum_exists(<figure number>):
        # Figure is still opened
    else:
        # Figure is closed
    

    The figure number of a figure is in fig.number.

    PS: Note that the "number" in figure(num=…) can actually be a string: it is displayed in the window title. However, the figure still has a number attribute which is numeric. The original string num value can however be used with fignum_exists() (since 2015, according to Mark H, in the comments).

    PPS: That said, subplots(…, num=<string num>) properly recovers the existing figure with the given string number. Thus, figures are still known by their string number in some parts of Matplotlib.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using matplotlib and numpy to make a polar plot. Here is some
is it possible to have an interactive session through pydev for using matplotlib? The
I'm currently using matplotlib to plot a measurement against 2 or 3 other measurements
I am using matplotlib in Python to plot a line with errorbars as follows:
I'm using Matplotlib to dynamically generate .png charts from a database. The user may
I'm trying to display a grayscale image using matplotlib.pyplot.imshow() . My problem is that
I'm using Matplotlib to plot a histogram. Using tips from my previous question: Matplotlib
I have a Python program that generates a histogram using matplotlib. The problem is
I need to plot some data in various forms. Currently I'm using Matplotlib and
Using Matplotlib via the OO API is easy enough for a non-interactive backend: from

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.