문제

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

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.

다른 팁

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

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top