No shell promt back after plot


4 posts
by Begat » Wed May 17, 2017 5:40 pm
Hi,
After getting a plot, the shell is not giving the prompt back.
Why? What could I do? Some shortcut I haven't found?
Pi3, Python 3.4.2 Shell, Plotting with 'matplotlib.pyplot' named 'plt' and used 'plt.show()'.
Posts: 2
Joined: Wed May 17, 2017 5:09 pm
by davef21370 » Wed May 17, 2017 6:59 pm
Post your full code using the Code tags in the forum editor.

Dave.
Please feel free to tap into my abundant lack of knowledge.
When you're dead you don't know you're dead. It's the same as being stupid.
Apple say. Monkey do.
User avatar
Posts: 824
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded
by robbes » Fri May 19, 2017 5:45 am
The call show() is a blocking call.
If you are done altering the figure, you can save it then close it. Closing it will return your shell prompt.
If you want to continue working with the plot, you might use the interactive mode:
Code: Select all
>>> import matplotlib.pyplot as plt
>>> plt.ion()    #interactive mode on
>>> plt.plot([1,2,3])   # example of a straight line

As you can see, you do not need to call plt.show() to see the output.
You can then continue adding to the same figure:
Code: Select all
>>> plt.plot([2,4,6])   # adding another straight line to the same figure
>>> plt.plot([3,6,9])  # adding yet another straight line to the same figure

or continue with any other python code.
Posts: 87
Joined: Sun Jan 20, 2013 7:11 pm
Location: Canada - off the west coast
by Begat » Sat May 20, 2017 10:34 pm
robbes,
Thanks for a very good answer.(I am a beginner to Python, trying to understand the syntax).
I had hoped there was a way to unblock the show() call without closing the figure (like ctrl+z). I have also used the interactive mode, but wanted to understand the use/meaning of show(), because it was used in a tutorial - without mentioning the blocking 'feature'.
Haven't tested it in a function yet (no access to Python at the moment), but it will halt the program also, or?
Posts: 2
Joined: Wed May 17, 2017 5:09 pm