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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:16:54+00:00 2026-05-25T13:16:54+00:00

In matplotlib, is there a simple way of plotting a figure without interrupting the

  • 0

In matplotlib, is there a simple way of plotting a figure without interrupting the control flow of the script?

Using pseudocode for clarity, here’s what I’m trying to achieve:

fig1 = figure()
fig1.plot_a_figure(datasets)

for dataset in datasets:
   results = analyze(dataset)    # this takes several minutes
   update(fig1)
   pop_up_another_figure(results) # would like to have a look at this one
                                  # while the next dataset is being processed

Of course, I can just savefig() these intermediate figures, but I only need a quick glance at a them and it would be the best to have them just pop up on the screen in real time.

EDIT: A runnable example:

#!/usr/bin/python
import pylab as plb
import matplotlib.pyplot as plt

fig1=plt.figure(1)
ax = fig1.add_subplot(1,1,1)

ax.plot([1,2,3],[4,5,6],'ro-')

#fig1.show()  # this does not show a figure if uncommented
plt.show()    # until the plot window is closed, the next line is not executed

print "doing something else now"

Am I missing something very very basic?

  • 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-25T13:16:54+00:00Added an answer on May 25, 2026 at 1:16 pm

    First things first, don’t forget a simple alternative is to just make new figure windows with plt.figure(2), plt.figure(3) etc. If you really want to update the existing figure window, you had better keep a handle on your lines object with

    h = ax.plot([1,2,3],[4,5,6],'ro-')
    

    And then later you would be doing something like:

    h[0].set_data(some_new_results)
    ax.figure.canvas.draw()
    

    As for the real meat of the question, if you’re still battling with this read on..


    You need to enable interactive mode if you want plt.show() to be non-blocking. To modify your runnable example so that “doing something else now” would print immediately, as opposed to waiting for the figure window to be closed, the following would do:

    #!/usr/bin/python
    import pylab as plb
    import matplotlib.pyplot as plt
    
    fig1=plt.figure(1)
    ax = fig1.add_subplot(1,1,1)
    
    ax.plot([1,2,3],[4,5,6],'ro-')
    
    #fig1.show()  # this does not show a figure if uncommented
    plt.ion()     # turns on interactive mode
    plt.show()    # now this should be non-blocking
    
    print "doing something else now"
    raw_input('Press Enter to continue...')
    

    However, this is just scratching the surface of things – there are many complications once you start wanting to do background work while interacting with the plots. This is a natural consequence of painting with what’s essentially a state machine, it doesn’t rub well with threading and programming in an object-oriented environment.

    • Expensive calculations will have to go into worker threads (or alternatively into subprocesses) to avoid freezing the GUI.
    • Queue should be used to pass input data and get results out of the worker functions in a thread-safe way.
    • In my experience, it is not safe to call draw() in the worker thread so you also need to set up a way to schedule a repaint.
    • Different backends may start to do strange things and TkAgg seems to be the only one which works 100% (see here).

    The easiest and best solution is not to use the vanilla python interpreter, but to use ipython -pylab (as ianalis has rightly suggested), because they have already figured out most of the tricks needed to get interactive stuff working smoothly. It can be done without ipython/pylab but it’s a significant amount of extra work.

    Note: I still often like to farm off worker threads whilst using ipython and pyplot GUI windows, and to get threading working smoothly I also need to use another commandline argument ipython -pylab -wthread. I’m on python 2.7.1+ with matplotlib v1.1.0, your mileage may vary. Hope this helps!

    Note for Ubuntu users: The repositories are still back on v0.99 for quite some time now, it is worth upgrading your matplotlib because there were many improvements coming up to the v1.0 release including a Bugfix marathon, and major changes to the behaviour of show().

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

Sidebar

Related Questions

Hi probably quite a simple question but.. When plotting a graph using matplotlib.pyplot my
Is there a way to save a Matplotlib figure such that it can be
Is there a quick way (without the overhead of using a GUI or graphics
Is there a function for drawing a caption box underneath a figure/graph using matplotlib?
I am using matplotlib and numpy to make a polar plot. Here is some
Is there a way to render a 3D pie in matplotlib, or is there
I am using matplotlib.pyplot.scatter to draw some simple scatter plot. However, something wrong appears
Is there a way to turn of the grid for polar plots in matplotlib?
Matplotlib has a function that writes text in figure coordinates (.figtext()) Is there a
I've got the following simple script that plots a graph: import matplotlib.pyplot as plt

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.