Is there a way for a python script to run to completion while backgrounding a matplotlib plot? The code below will block until the plot is closed.
import matplotlib
from matplotlib import pyplot as plt
x = [0,1,2,3,4]
plt.plot(x)
plt.show()
Setting plt.show(block=False) prevents the plot from ever showing up.
Clarification on running:
From a linux shell, running python example.py, which contains the code above, should run and return to the linux prompt while the plot stays up. Currently the plot will block the completion of the python script.
Related
I am trying to plot some scientific data by using Matplotlib in terminal.
here is my simple code :
import matplotlib.pyplot as plt
plt.plot([1,2,3],[3,2,5])
plt.show(block=True)
But I can't see any graph on my linux.
I am using wsl on windows for linux.
debian is my linux.
The link below doesn't help my problem:
Matplotlib plots aren't shown when running file from bash terminal
as you see I set block to True and nothing! for now I am using plt.savefig() function to see my result in windows.
may be I need to install some software in my Linux for image viewer , no?
thank you
Attempting to get some very basic stuff working on my Windows 7 machine. If I run the below from the matplotlib documentation:
Script 1:
import matplotlib
matplotlib.use('qt4agg') #Just using this to test backends
import matplotlib.pyplot as plt
plt.ion()
plt.plot([1.6, 2.7])
Then I should get a line plotted and be able to change things via the terminal prompt. What actually happens is I get a blank figure and a spinning wheel, 'python.exe is not responding' and needs to be forced closed.
If I put:
Script 2:
import matplotlib
matplotlib.use('qt4agg') #Just using this to test backends
import matplotlib.pyplot as plt
plt.ioff()
plt.plot([1.6, 2.7])
plt.show()
Then I get the desired result but my terminal prompt is blocked from use.
The other thing is that the above are both run using the QT4Agg backend which is not what I want to use. Testing a couple of other backends (GTK3agg and Tkagg) I get the following results:
GTK3Agg
ION - Same error as when running with Qt4Agg, I get a blank figure and a spinning wheel, 'python.exe is not responding' and needs to be forced closed.
IOFF - Blank figure appears but no spinning wheel and I get 'python.exe has stopped working' immediately after the figure appears
Tkagg
ION - Blank figure appears but no spinning wheel and I get 'python.exe has stopped working' immediately after the figure appears
IOFF - Blank figure appears but no spinning wheel and I get 'python.exe has stopped working' immediately after the figure appears
I need to get it working with the other backends but as currently I can at least get the non-interactive one to work with qt4agg, getting the interactive one working with that seems like a good place to start. Any ideas?
I'm running Python 3.5.1 with matplotlib version 1.5.1 and iPython 5.0.0. I can't seem to get matplotlib's interactive feature working. I can run a command to create a plot:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1,2,3])
This doesn't show a figure until I manually execute plt.show(), at which point iPython hangs until I close the figure window. I have interactive set to True in my matplotlibrc file.
It's been a year or so since I used matplotlib. The last time I used it, I got interactive without having to execute plt.show(). Has something changed or am I doing something wrong?
You were probably using interactive mode previously.
Start ipython with:
ipython --pylab
Then your plots will show up instantly.
I am working in python and using Anaconda with Spyder and I need to plot a scatter plot in a part of the code I am working on. The plot is just fine but is drawn in the console itself and the size is quite small for my needs.
My question is, how can I plot it in another window outside the ipython console? I already tried changing some of the setting like changing Graphics setting in ipython from inline to QT to tkinter. Nothing seems to work.
Any helpful suggestions?
you can just save %matplotlib qt in a .py file and you can start ipython using:
ipython -i myfile.py
I was practicing plotting in matplotlib, and I noticed that the following code works correctly when I run it as one big chunk, but not when I enter it line by line into the console (a blank figure window shows up, but the line does not). What gives?
import matplotlib.pylab as plt
fig,axes=plt.subplots()
axes.plot([1,2,3],[2,3,4])
plt.show()
I'm running Enthought Canopy, Python 2.7.6., matplotlib 1.3.1
Thanks!
P.S. What I find even stranger is if I subsequently type fig into the console, all of a sudden the correct plot pops up in the figure window.