If I run a Python program under the debugger in VSCode, and the program
has the line import matplotlib.pyplot as plt, I see the following
message in the Python Debug Console (under the TERMINAL tab):
Backend TkAgg is interactive backend. Turning interactive mode on.
This is desired, as now I don't have to type plt.show() after every
plt.plot() when I'm exploring data in the REPL under the
DEBUG CONSOLE tab.
The problem is, not every program has that import line, and so I'm
forced to manually do so in the debug REPL, and follow each plt.plot()
with a plt.show().
My question: Is there a way to force this 'interactive mode',
perhaps through the launch.json file? I've looked at the docs for launch.json
but don't see anything applicable.
I'm using VSCode 1.63.2 on Windows 10 Version 20H2.
I have been running into a trouble whereby Spyder IPython console is not producing Matplotlib figures as desired. I thought initially that there is something wrong in my code since jupyter notebook gives me the same wrong figures. However, when running the script in Spyder using external terminal the figures are produced as desired. Also, when I run the code in VSC the correct figures are displayed.
So the only option I am left with in Spyder is to use the external terminal to execute the code. However, it is quite a pain every time to run some codes and then manually close the terminal.
I would like to know if there is a way to permanently attach the external terminal inside Spyder? I hate the IPython console when it comes to plotting matplotlib figures!!
(Spyder maintainer here) Sorry but there's no way to dock an external Python terminal inside Spyder.
Matplotlib hangs now that I've upgraded to Sierra.
The behavior is different depending on how I run it.
In a file (running with %run <filename> inside of ipython or python <file name> from the terminal):
The terminal will hang on import (import matplotlib.pyplot as plt) and all I get is the little rocket icon bouncing in my dock.
Directly from ipython:
I can import it and show a plot, but it will hang once I try to close the figure window. Doing this from inside of the basic python shell does not have this problem. So it seems running in interactive mode also causes hanging.
Has anyone experienced something similar?
python version: 3.5.2
matplotlib version: 1.5.1
backend: MacOSX
OSX: 10.12.2
Switching to a TkAgg backend will display the figure window, but it will hang on plotting (in interactive mode).
Note
Setting up a virtual environment to run python 2.7 with a TkAgg backend works as expected
Seems to be a caching issue:
running:
cd ~/.matplotlib
fc-list
fixed the problem (same issue discussed here: import matplotlib.pyplot hangs but the symptoms were a little different)
I have read tons of questions on this, but I am still baffled. I'm running Anaconda in Scientific Linux. I launche a console a type ipython qtconsole.
My script.py is something like
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5,6,7,8,9,10])
plt.show()
I type run script.py from the qtconsole, and the program just sits and does nothing. What am I doing wrong? I have been using the qtconsole for running my scripts, maybe it's better for really being interactive with and I should be running my scripts some other way?
Any general advice on workflow would be very helpful here. When should I use python script.py, when should I use ipython script.py, and when should I use the qtconsole, etc...?
This seems like a Magic Function problem
More specifically %matplotlib. %matplotlib inline will show it within the browser, or you can replace inline with whatever you feel better for your use.
This is a follow up to this interactive matplolib through eclipse thread which is about 2 years old, I was wondering if there has been any progress in the meantime.
I am running the IPython console in a console window in Eclipse PyDev, but I am unable to get the same interactive plotting features with matplotlib as if I were to run IPython in a (Windows) command prompt outside Eclipse PyDev. Here is how the two compare:
A) Running IPython in a shell outside Eclipse PyDev
Run IPython in a Windows command prompt with "ipython --pylab"
Within the IPython console enter "plot([1,2,3])". This will open a figure plot window and the IPython console is ready for further commands (without having to close the figure plot window).
For example, I can enter "xlabel('years')" and this will update my figure plot window.
B) Running IPython in an interactive console within Eclipse PyDev
Enter the following in the IPython interactive console within Eclipse PyDev:
"from pylab import *"
"plot([1,2,3])" --> Figure plot window does not show up.
I have to enter "show()" to open the figure plot window. But now the problem is that as long as I keep the figure plot window open, the IPython console does not accept any new commands.
So I close the figure plot window, enter "xlabel('years')", followed by "show()" again. This will re-open the figure plot window with "years" as my axis label, but the plot itself is empty and does not show the [1,2,3] data anymore.
With this behaviour, A) is clearly superior to B), but I would like to keep working in Eclipse PyDev because I like always having the variables list on my screen (without having to run a command to show all variables like when running IPython form a windows shell). Using Wicked Shell, as suggested in the other thread, does not work (IPython does not work properly in Wicked Shell).
How can I configure IPython in Eclipse PyDev so that it shows the same interactive behavior as if I would run it in a windows command prompt?
You can solve this problem by selecting a GUI for the Interactive Console in PyDev Preference.
Eclipse -> Window -> Preferences -> Pydev -> Interactive Console -> Enable GUI event loop integration.
In my case, I chose PyQt (qt/qt4)
Apologies for the potentially incomplete answer, but hopefully I will be able to shed some light on the problem.
I believe that the one that the OP describes is normal behaviour. In fact, starting from the command line ipython, importing pylab and issuing a plot command produces exactly the blocking behaviour described, so this is not related to pydev or eclipse. The fact is that show in matplotlib is blocking in interactive mode; when you use matplotlib in a ipython session started as "ipython --pylab", you are taking advantage of some "hacks" that the ipython developers did for you around matplotlib, allowing to have both an interactive mode and non blocking calls. However, importing pylab is not enough to apply these "hacks". PyDev does not seems to allow flags to the interpreter call, so one can't directly invoke "ipython --pylab".
Luckily, ipython has a special command "pylab" that applies the hacks and imports pylab even if the interpreter was not started with the pylab flag. So you can just try to type "pylab" inside the console (actually, you can even customize your pydev console so that it is done automatically) and you should get the desired behaviour. However, I must report that while this works fine for me from a ipython session started from the command line, something goes wrong when I try to do the same from inside Eclipse. The command doesn't block, I get the python icon but the matplotlib window doesn't show up. For the records, I am on a Mac running Snow Leopard. I am not able to tell if the same problem happens also in Windows, that the OP seems to be using.
I achieve similar behave in Eclipse PyDev by executing plotting function in another thread:
import threading
from pylab import *
import matplotlib.animation as animation
import time
x = array(range(0,1000))/100
y = sin(x)
def updateData(self):
ax.set_data(x,y)
def MyThread():
global ax
fig, axarr = subplots(1)
ax, = axarr.plot(x,y)
simulation = animation.FuncAnimation(fig, updateData)
show()
t = threading.Thread(target=MyThread)
t.start()
# console stay active, user can interactively control figure
time.sleep(1)
y = sin(2*x)
time.sleep(2)
ax.get_axes().grid()
ax.get_axes().set_xlabel("time")
Tested with toolchain Eclipse 4.3, PyDev 2.7.1, Python 3.2, IPython 0.13
Just use the %matplotlibmagic-command to activate interactive plotting (exactly what you described).
The pylab command imports numpy.* and pylab.*, seriously polluting your global namespace.