No shell promt back after plot

4 posts
by Begat » Wed May 17, 2017 5:40 pm
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 ''.
Posts: 6
Joined: Wed May 17, 2017 5:09 pm
Location: Sweden
by davef21370 » Wed May 17, 2017 6:59 pm
Post your full code using the Code tags in the forum editor.

Apple say... Monkey do !!
User avatar
Posts: 868
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 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: 88
Joined: Sun Jan 20, 2013 7:11 pm
Location: Canada - off the west coast
by Begat » Sat May 20, 2017 10:34 pm
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: 6
Joined: Wed May 17, 2017 5:09 pm
Location: Sweden