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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:48:10+00:00 2026-06-11T04:48:10+00:00

Possible Duplicate: How to make the plot not disappear? I am writing a command

  • 0

Possible Duplicate:
How to make the plot not disappear?

I am writing a command line interface python program for analysing some data. It asks the user a bunch of questions and at a few points in the script a matplotlib pyplot plot neds to be shown, but I want to show it and continue with the script something like below:

import matplotlib.pyplot as plt
import numpy as np

plt.figure()
plt.plot(np.arange(10),np.arange(10)**2)

plt.show()
print 'continuing the program'

I have tried using plt.draw() along with subplots but it doesn’t seem to work inside a script.

edit:
I have used plt.ion() which kind of works except the plot windows are unresponsive, and the zoom in tool etc buttons aren’t shown

  • 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-11T04:48:11+00:00Added an answer on June 11, 2026 at 4:48 am

    plt.show() will not return until the user closes the widget/window. I many cases this behavior is fine. Why should the script proceed while the user spends time looking at a wonderful graph anyway? 🙂 If you, however, require your program to proceed, make use of the threading module. Invoke plt.show() in a new thread and join() this thread before letting your main thread terminate.

    Edit:

    It looks like things are not that simple. I created the following test.py:

    import threading
    from matplotlib import pyplot as p
    import time
    
    p.plot([_ for _ in xrange(5)])
    
    t = threading.Thread(target=p.show)
    t.start()
    
    for i in xrange(5):
        print "lala %s" % i
        time.sleep(1)
    
    print "Waiting for plot thread to finish..."
    t.join()
    print "Finished."
    

    Testing it results in this error:

    14:43:42 $ python test.py
    lala 0
    lala 1
    Exception in thread Thread-1:
    Traceback (most recent call last):
      File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
        self.run()
      File "/usr/lib/python2.6/threading.py", line 484, in run
        self.__target(*self.__args, **self.__kwargs)
      File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_tkagg.py", line 73, in show
        manager.show()
      File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_tkagg.py", line 385, in show
        if not self._shown: self.canvas._tkcanvas.bind("<Destroy>", destroy)
      File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 988, in bind
        return self._bind(('bind', self._w), sequence, func, add)
      File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 938, in _bind
        needcleanup)
      File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1101, in _register
        self.tk.createcommand(name, f)
    RuntimeError: main thread is not in main loop
    

    I infer from this that p.show() is required to be called from the main thread. Maybe you have to do it the other way round: get your user input in another thread.

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

Sidebar

Related Questions

Possible Duplicate: How can I make an EXE file from a Python program? i
Possible Duplicate: How to make python scripts executable on Windows? Set up Python on
Possible Duplicate: How to make return key on iphone make keyboard disappear? I have
Possible Duplicate: Platform independent paths in Java I make a program but it save
Possible Duplicate: Sleep Less Than One Millisecond How can I make a program sleep
Possible Duplicate: License for C# desktop application I want to make my program lock
Possible Duplicate: How can I make a fieldset legend-style background line on heading text?
Possible Duplicate: How to make a python dictionary that returns key for keys missing
Possible Duplicate: How to make data member accessible to class and subclass only In
Possible Duplicate: Make error: missing separator I am so stressed out by this silly

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.