Begat
Posts: 6
Joined: Wed May 17, 2017 5:09 pm
Location: Sweden

No shell promt back after plot

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()'.

User avatar
davef21370
Posts: 874
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: No shell promt back after plot

Wed May 17, 2017 6:59 pm

Post your full code using the Code tags in the forum editor.

Dave.
Apple say... Monkey do !!

robbes
Posts: 90
Joined: Sun Jan 20, 2013 7:11 pm
Location: Canada - off the west coast

Re: No shell promt back after plot

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.

Begat
Posts: 6
Joined: Wed May 17, 2017 5:09 pm
Location: Sweden

Re: No shell promt back after plot

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?

Return to “Python”

Who is online

Users browsing this forum: tulaaks and 19 guests