I have a program written using PyQt and Matplotlib which I am using to display stellar spectra.
The program has a dialog box which I can use to select the required spectra and adjust the X/Y scales and other things.
When changes are made in the dialog box, I have the code do (with matplotlib.pylab imported s plt)
plt.clf()
(replot the newly-selected spectra)
plt.show()
This works fine with older versions of Matplotlib (1.0.0)
However with later versions of Matplotlib (I'm trying 1.3.1), I get strange results. I'm OK the first time round but each subsequent attempt fails to update the plot. I also get lots of messages:
QCoreApplication::exec: The event loop is already running
each time the program tries to invoke the above code and the plot is not updated.
If I change the last part of my code to say
plt.show(False)
That makes the messages go away but the plot is still not updated.
The only way I can make the plot get updated is to change the
plt.clf()
to
plt.close()
but that looks horrible as the display window closes and reopens every time I select a different spectrum.
Is there a better way of doing all this?
I'd rather use the new version of Matplotlib if I can as I also need to use the newer versions of Scipy which has routines in I am using which aren't in the older versions. At the University I'm working it's either "all old" or "all new" as far as versions of the software are concerned.
Thanks for any help you can give.
Solution by OP.
I do:
matplotlib.interactive(True)
and don't bother with any parameters to show() and it does what I want.
Related
So I am trying to get the screen size without the taskbar, and through reading around I found that the only reliable way was to get the "working area" of the screen (Especially since I might be using multiple screens.), then subtract it from the screen size
Now, my issue is that the working area I am getting is equal to the screen size, which means it is not showing my the actual working area. I have tried some different solutions, and the codes are straight forward.
Dim workingArea = My.Computer.Screen.WorkingArea
This would give me back 1920x1080 which is the same as my resolution. I am not using an auto hide taskbar, and I am not sure what's the issue with this, and/or if there is a better way to do what I am trying to do.
Edit: I have tried to use the DPI aware as per the last comment (following the steps in Using SetWindowPos with multiple monitors)
I am quite confused why I am not getting the correct number here, any feedback is appreciated.
Edit2:I have tested this code itself in another PC and it was a similar result, I will attempt to install an older version/newer version of visual studio or another .net version, however the issue is still illogical, and no solutions seem to be working (with one or more screens having the exact same feedback.)
Edit3: The task bar does not hide, testing the numbers still shows the same regardless of the number of screens, different resolutions were the same as well.
Is there a way to make plots appear in an integrated window on spyder (like in the help space) instead of inline (not practical and no way to zoom) and not as a pop-up window (in my case it always appears on a different space as I use spyder in full screen mode)?
I tried the OSX/Qt4/QT5 settings and they still appear on a separate window.
I would want the same setting as in RStudio where I can go back and forth between plots and not have to deal with windows 'floating' around. Is there a way to work it that way or it does not exist yet?
(Spyder maintainer here) A dedicated pane that shows all plots generated in our consoles is already implemented and will be part of our next major version (Spyder 4, to be released in 2019). Here you can find some screenshots of that pane.
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()
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?
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.