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.
Related
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 using the Jupyter notebook with Python 2.7. Importing matplotlib like this:
%matplotlib inline
import matplotlib.pyplot as plt
But I have observed one thing. When I use Python in Spyder I always have to use the plt.show() command at the end of the python script in order to see the plots.
In Jupyter I do not need this command in order to see a plot. I do get this error message:
[<matplotlib.lines.Line2D at 0x91615d0>]
but it still makes a plot. Why is that?
You turn on the immediate display with %matplotlib inline.
The line:
[<matplotlib.lines.Line2D at 0x91615d0>]
is no error message. It is the return value of the last command. Try adding a ; at the end of the last line to suppress this.
The requirement of adding %matplotlin inline is no longer needed in the latest jupyter notebooks. It's a by default addition now.
You can change settings in ipython_kernel_config.py for different behaviour
I am trying to run python in XCode. The following simple plotting routine,
import matplotlib.pyplot as pyplot
pyplot.plot((0,1),(1,2))
pyplot.show()
returns no errors. XCode seems pretty happy with what it accomplishes when I hit the run button. But I get no plot window whatsoever, as far as I can tell. Is it hiding somewhere or what? How do I get to see it?
xcode will allow you to see plots if you move your code into an interactive notebook.
create a new file with the .ipynb file extension
copy your code into that file
You should be able not only to see the plots but also any other output your code is trying to send to the UI.
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