matplotlib interactive… isn't - python

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.

Related

How to run a python script so matplotlib plot does not block

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.

matplotlib doesn't plot in terminal

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

Jupyter shows plot without plt.show()

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

Plot plotted inside the ipython console

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

Plot inside Ipython Notebook

I'm using IPython notebooks to share code and (hopefully) graphics with m collaborators. sadly, I cannot get matplotlib to plot inside the notebook, it always gives me a pop-up window, which I obviously cannot include in notebook pastes or similar.
Here's two minimal examples of how I go about plotting things.
Either with invoking plt.show() , or without it.
this either gives me an external pop-up, or plots nothing.
You need to be using the matplotlib inline backend.
%matplotlib inline

Categories

Resources