2
votes

This file should work, but it doesn't:

from matplotlib import pyplot

pyplot.ion()
pyplot.plot(range(10))

raw_input('Press return to close')

The plot window appears, the inside is white and the hourglass cursor is shown. The text is printed in the shell, and hitting return closes the empty plot window.

I can plot from ipython, but this has to run from a file. Exactly the same problem as Using ion() from pylab causes matplotlib to hang , but the solution doesn't help me.

I am using Qt4Agg, by default. I haven't changed any settings, it is a fresh Anaconda install.

I don't think this is Anaconda specific, I had exactly the same problem some time ago with a normal Python install, but I don't remember the solution.

I recently upgraded Matplotlib to 1.3.1 np18py27_1

Current conda install:

             platform : win-32
        conda version : 3.0.6
       python version : 2.7.6.final.0
     root environment : C:\Anaconda  (writable)
  default environment : C:\Anaconda
     envs directories : C:\Anaconda\envs
        package cache : C:\Anaconda\pkgs
         channel URLs : http://repo.continuum.io/pkgs/free/win-32/
                        http://repo.continuum.io/pkgs/pro/win-32/
          config file : None
    is foreign system : False
3
I had problems on windows with ion() as well while my code worked fine on linux. For me it helped to introduce a very short pause which enabled windows to not show a white window. The code I needed to include was: pylab.pause(1.e-6). Does this work for you as well? - The Dude
When I put the pylab.pause(1e-6) after the plot, the plot appears, but is not interactive. Very strange. Do you have any idea what is going on? - user1508010
In what sense is it not interactive? It will require you to plot more than you provided in your code. After each plot you should have pyplot.draw(). With this piece of code the interactive plot is updated with the new data. - The Dude
Sorry I wasn't clear. With interactive I meant that I can't interact with the plot anymore. When I do ion, plot, raw_input, I get a white window with nothing. ion, pause, plot, raw_input is the same. ion, plot, pause, raw_input draws the plot, but the window then freezes and I can't zoom. When I pause for 10 seconds, I can zoom for 10 seconds, and then it freezes. - user1508010
This is strange, because the code in my question is very basic, I've been using that for many years. It works on other machines, too. - user1508010

3 Answers

1
votes

If it fixed your problem to call a different back-end, you can make this a permanent change by changing the matplotlibrc file.

Unfortunately, I'm not sure where this file would be in windows.

When you do find it, line 32 sets the back-end used:

#### CONFIGURATION BEGINS HERE

# the default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# CocoaAgg FltkAgg MacOSX QtAgg Qt4Agg TkAgg WX WXAgg Agg Cairo GDK PS
# PDF SVG Template
# You can also deploy your own backend outside of matplotlib by
# referring to the module name (which must be in the PYTHONPATH) as
# 'module://my_backend'
backend      : <Whatever works for you>

This will allow you to run it from a file - outside of ipython

0
votes

I'm guessing you want something like this. It works fine under linux. Since the pause of 1.e-6 seconds is included it should also work on windows.

import sys
import select
from matplotlib import pyplot


def heardEnter():
    i,o,e = select.select([sys.stdin],[],[],0.0001)
    for s in i:
        if s == sys.stdin:
            input = sys.stdin.readline()
            return True
    return False

pyplot.ion()
pyplot.pause(1.e-6)

print "Press enter to exit plotting"

cont = 1
while cont:
    pyplot.plot(range(10 + cont))
    pyplot.draw()

    cont += 1
    if heardEnter():
        cont = False
0
votes

The answer was embarrassingly simple,

ipython qtconsole --matplotlib

The "trick" is to add the option --matplotlib. Running the IPython-qtconsole from the Anaconda launcher omits this, I don't know why. At least it should give a warning on pyplot.ion() if it doesn't support interactive plotting.