Interactive Plotting

I notice that when using the IPython console interactive plotting doesn't work - by default you have to manually call show() which then blocks until the figure is destroyed.

If you try to turn on interactive (non-blocking) plotting with the %pylab magic the console doesn't block but the figure doesn't display properly.

Is there any chance interactive plotting can be enabled in a future release?

Thanks,
Dave

 print IPython.sys_info()
{'commit_hash': 'c6b7529',
'commit_source': 'repository',
'default_encoding': 'UTF-8',
'ipython_path': 'c:\\dev\\code\\ipython\\IPython',
'ipython_version': '0.14.dev',
'os_name': 'nt',
'platform': 'Windows-7-6.1.7601-SP1',
'sys_executable': 'C:\\dev\\bin\\Python27\\python.exe',
'sys_platform': 'win32',
'sys_version': '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'}
0
19 comments
Maybe related: http://youtrack.jetbrains.com/issue/PY-7029. Please describe your actions for plotting your data in more detail.
0
Avatar
Permanently deleted user
Yep, that looks like the same issue. This issue has been seen with IPython previously and IIRC has to do with the correct handling of the gui event loop.

To add a little more explanation, when not in "interactive" plotting mode calling `show` will display the figure correctly but will block the console. After turning on "interactive" plotting the figure will pop up immediately after a call to `plot`, the console won't block but the plot won't display correctly and will effectively hang until a call to `close('all')` closes the figure window.


Console Session
PyDev console: using IPython 0.14.dev
import sys; print('Python %s on %s' % (sys.version, sys.platform))
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
>>> from pylab import *
>>> x = randn(1000)
>>> plot(x)
Out[5]: [<matplotlib.lines.Line2D at 0x54af7f0>]
>>> show() # Figure now shows correctly but console blocks
>>> # Closing the figure returns control back to the console
>>> ion() # turn on interactive plotting
>>> plot(x) # returns control back to the console immediately
Out[9]: [<matplotlib.lines.Line2D at 0x5982990>]
>>> # Figure window has popped up, but doesn't display anything
>>> # and has (Not Responding) in the title bar
>>> # The close button on the figure doesnt work
>>> close('all') # will close the figure
0
Avatar
Permanently deleted user
Sorry, posted a new comment (below) instead of replying...
0
Avatar
Permanently deleted user
Unlike Pycharm, ipython has a transparent resolution to this. All you have to do is use ipython's –pylab switch:

plt (804B)

Yes, the workaround with Pycharm is to add a show() after the plot() call. But that Way results in the console being locked out until the Tkinter window is closed as is the case with ipython without its –pylab switch.

If Jetbrains could figure out a '–pylab' sort of enhancement to PyCharm, that would be great.
0
Avatar
Permanently deleted user
Is that issue going to be fixed? interactive plots inline with pycharm console? I see that issue was raised over a year ago and I didnt see no solution. can someone shed more light over this?
0
Avatar
Permanently deleted user
Hi idoda, there will be no inlined plots in PyCharm console in the near future due to technical feasibility. The thing that probably will be made soon is working PyCharm console with plotting in external window.
0
Avatar
Permanently deleted user
So currently there is no way of creating plots with pycharm?
0
Avatar
Permanently deleted user
Plots are generated, but not inline, only in a separate window.

Also if you call pylab with magic command (%pylab), then plots do not work
If you import pylab (from pylab import *), then plots work, but require additional plt.show() command.

ipython1.png

ipython2.png
0
Avatar
Permanently deleted user
Unfortuantely the plot window blocks everything until it has closed, crippling its usefulness. Unless this has changed recently?
0
Avatar
Permanently deleted user
There is really no hope for this.  It is just a lost cause.  Spyder and IEP, which actually try to be interactive environments for matplotlib, can't do this either.

It turns out that PyCharm offers the best support of all three of these products though you may not like how it works:
1.  open a terminal window  (PyCharm will open it in your project directory.)
2. run ipython
3. import your script
4. dynamic charting works.

There may be some way to create an external command that does this along with the import.  I'll try that though I am fully satisfied with what I described given how much time I wasted on IEP and Spyder.  Nice folks in both bases, but neither could solve this.
1
Avatar
Permanently deleted user
I don't use IEP so I can't speak to that, but in the IPython QtConsole and hence also in Spyder you can plot without blocking the terminal so yes, it is possible and other projects do implement it properly.

Your suggestion 1-4 basically boils down to don't use PyCharm for interactive plotting / data analysis which is exactly the situation we have now and isn't a solution to the limitations of PyCharm.

The discussion here and on PY-12096 and PY-7029 shows that there is a lot of demand for this feature. The last word from a PyCharm dev is that Alexander Marchuk is looking into it so I'm eagerly awaiting any developments there.

One alternative that may be easier to implement would be a bokeh plotting solution - IIUC you could have a persistent bokeh server which the IPython could talk to via the Python bokeh package.

  • Dave
0
Avatar
Permanently deleted user
I have recently switched to python from matlab so I have little experience with the tools as well as little understanding. I have encountered discussed issues both in pycharm and ipython. The problem disappears however if you execute iptyhon with "–matplotlib qt" switch. Not sure if this is applicable to pycharm though.
0
Avatar
Permanently deleted user
I think I've found a workaround for pycharm. Adding the following at the beginning of a python script seems to solve the problem on windows:

import matplotlib as mpl
mpl.use('Qt4Agg')

The startup is a little longer though.
0
Avatar
Permanently deleted user
I can confirm that that doesn't work on windows. The plot either blocks the console or is completely black.
0
Avatar
Permanently deleted user
Perhaps the devil is hidden in some details. I've first installed Enthought Canopy distribution and used their IDE for a while (on Windows). I had no problems with the plots there. I've later switched to pycharm, which uses python 2.7 from the Enthought installation. I also have Qt SDK installed separately but that should not matter.
Anyway, I hope that the issue will be solved in Pycharm.
0
Avatar
Permanently deleted user
I commented on PY-7029 but I will reiterate here - JetBrains, there are legions of MATLAB users out there who would GLADLY become loyal PyCharm users instead if you could just please, please, PLEASE make simple interactive plotting work from the IDE console.  Did I say PLEASE? :)  And thanks!
0
This is not a direct solution to the problem, but a workaround for those on Linux / OSX :

I started working on a plugin to get something like MATLAB cell mode in PyCharm. Cells are delimited by ## and my plugin can send the cell content (python code) to either the internal console or an external ipython running in tmux. With the second solution (external ipython in tmux), matplotlib interactive plotting works.

You can get the plugin here (download PythonCellMode.jar and install plugin from disk in PyCharm) :
https://github.com/julienr/pycharm-cellmode

It's alpha quality at the moment, but it seems to work for me.
0
Hi,

I solved this issue in OS X Mavericks with the following steps:

1) Install PySide. I used the following guide:
http://www.pythoncentral.io/install-pyside-pyqt-on-windows-mac-linux/

2) Run the following script before plotting. You may want to add this to PyCharm - Preferences - Build,Execution,Development - Console - Python Console - Starting script.

import matplotlib as mpl
mpl.rcParams['backend.qt4'] = 'PySide'
mpl.use('Qt4Agg')
from pylab import *
ion()

This enables interactive plotting for me. For example, when I run:

x = arange(0,10,0.1)
y = sin(x)
plot(x,y)

The plot renders in a separate window, and the control returns to the console immediately.
0
Avatar
Permanently deleted user
While this is an ancient thread, I only thought it appropriate to reply that this is fixed in Python 4.6 and 5.0.  

It is important to use pt.show() (Or pylab.show()–depending on how you import matplotlib) to cause drawing.  I also think that matplotlib.pyplot.ion() and ...ioff() work as expected.
0

Please sign in to leave a comment.