how to close plot show in ipython matplotlib - matplotlib

I used ipython and plot a graph and type plt.show().
This pops up a graph window. But, when I close the window,
the ipython does not go back to prompt and stays non-responding.
How can I close the graph window properly and go back to ipython ?
Thanks.

Related

How to plot in a new window in Spyder-IDE(Python)

My Spyder-IDE prints the plots in it's ipython console. How can I change the settings to do plotting on a new pop-up window?
You need to go to the menu
Tools > Preferences > IPython console > Graphics > Graphics Backend
and select the option called Automatic there.
After doing that you need to restart either Spyder or the console kernel for this change to take effect.

python 3 figures freeze on ubuntu

I have a very strange bug. When opening figures in python, if I hover the mouse cursor above the figure toolbar, everything freezes for about a minute.
I tried:
1. Both from Spyder and using python from bash.
2. Using tkAgg as well as WX and Qt5Agg. By setting before plotting: ,e.g., matplotlib.use('Qt5Agg')
The behavior was similar in all cases.
Would appreciate any advice here. My OS is Ubuntu.

Use matplollib.pyplot without opening graph window

This might sound weird but I'd like to know if it is possible.
The reason why I'm asking this is because I work on a sound recognition code and I use the plt.specgram() function.
My problem is that when I'm putting a sound sample, I don't want to see the graph because I don't need it. It is more annoying than helping...
I tried using pylab.specgram() instead but the graph window keeps on showing.
Thank you in advance !!
I guess you are using pylab mode. By default, pylab will show the plot ("interactive mode").
You can stop interactive mode by:
plt.ioff()
pylab.ioff()
ioff() # if name space is 'from pylab import *'
This should stop showing/updating the plot every time you call some plotting function.
Once you have done drawing, you can do one of those:
plt.show()
pylab.show()
show()
Also, when you want the interactive mode back on:
ion()

Matplotlib backend lets me either have interactive window or use pyplot.close('all') withouth an error

I am using ipython with python3.4 via a virtualenv and had to change matplotlib's backend in order to have the interactive plotting window show up. But when I try to plot not in the ipython shell but import a script that does the plotting for me, I can not use pyplot.close('all') (therefore multiple open windows are lingering in the back that can be open with plt.show())without getting the error:
can't invoke "event" command: application has been destroyed
while executing
"event generate $w <<ThemeChanged>>"
(procedure "ttk::ThemeChanged" line 6)
invoked from within
"ttk::ThemeChanged"
I can get rid of this behavior by explicitly using matplotlib.use('agg') but then pyplot.show() is of course not working anymore. I guess i fundamentally do not understand how to choose an appropriate backend. When I use matplotlib.get_backend() it gives me 'TKAgg'.
Is it possible to be able to close windows in a script while being able to open interactive windows or is this behavior generally not wanted?

PythonXY, IPython Qt Console, matplotlib, draw something not in inline mode

I'm new to PythonXY and Matplotlib. I installed PythonXY (v2.7.3.1) in default full mode.
I use the "IPython Qt Console" application.
I draw something using matplotlib.pyplot (imported as plt).
For example. When plt.plot([1,3,2,4]), the figure display in the same IPython console immediately.
If this, I cannot add some other properties, plt.title, plt.xlabel, plt.ylabel, or more. Why? And how can I draw figures in another window, adding more properties, and making the figure not display until plt.show()?
If you select from the Interactive Consoles dropdown on the Python(x,y) Home launcher, "IPython (Qt)" and then click either the Console 2 or cmd.exe button, it should then run IPython (Qt) with the Qt4Agg backend which will allow you to plot in a separate window and apply titles and so on. For more info see What is a backend.
What Python(x,y) in your example above is doing is launching IPython with the pylab inline backend which is different from the standard backends so your commands aren't having any affect, similar behaviour is noted in this issue on github. It doesn't seem possible to change the backend once IPython has been launched with inline. I'm not sure where the Python(x,y) options are set or which script is called to launch the item in the Applications dropdown.
Worth taking a look at Anaconda as a free Python distribution with a scientific focus and regular updates. Anaconda doesn't by default load pylab into IPython so you can choose the backend after launching IPython.
In the IPython command-line interface, the figure is shown and updated at each plot function.
With the inline option, Matplotlib generates an image that automatically inserted in the output line.