Backtrace with CocoaAgg backend

Hi

I'm trying to track down an issue with the CocoaAgg backend on Mac OS
X using MacPorts, when run with the CocoaAgg backend the following
code:

from pylab import *
import time

ion()

tstart = time.time()
x = arange(0,2*pi,0.01)
line, = plot(x,sin(x))
for i in arange(1,200):
    line.set_ydata(sin(x+i/10.0))
    draw()

print 'FPS:' , 200/(time.time()-tstart)

fails with the backtrace:

$ python temp.py -dCocoaAgg
Traceback (most recent call last):
  File "temp.py", line 2, in <module>
    from pylab import *
  File "/opt/local/lib/python2.5/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/opt/local/lib/python2.5/site-packages/matplotlib/pylab.py",
line 253, in <module>
    from matplotlib.pyplot import *
  File "/opt/local/lib/python2.5/site-packages/matplotlib/pyplot.py",
line 75, in <module>
    new_figure_manager, draw_if_interactive, show = pylab_setup()
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/__init__.py",
line 25, in pylab_setup
    globals(),locals(),[backend_name])
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_cocoaagg.py",
line 54, in <module>
    class FigureCanvasCocoaAgg(FigureCanvasAgg):
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_cocoaagg.py",
line 63, in FigureCanvasCocoaAgg
    start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__
NameError: name 'FigureCanvasBase' is not defined

However this runs without issue using the MacOSX backend:

$ python temp.py -dMacOSX
FPS: 20.1183278689

Is there some missing dependency that could cause this?

Cheers

Adam

Sorry, should have mentioned that this is with Matplotlib-0.98.5.2
using Mac OS X Leopard.

Cheers

Adam

···

On Sat, Jan 17, 2009 at 17:19, Adam Mercer <ramercer@...287...> wrote:

Hi

I'm trying to track down an issue with the CocoaAgg backend on Mac OS
X using MacPorts, when run with the CocoaAgg backend the following
code:

Anyone?

Cheers

Adam

···

On Sat, Jan 17, 2009 at 17:19, Adam Mercer <ramercer@...287...> wrote:

Hi

I'm trying to track down an issue with the CocoaAgg backend on Mac OS
X using MacPorts, when run with the CocoaAgg backend the following
code:

from pylab import *
import time

ion()

tstart = time.time()
x = arange(0,2*pi,0.01)
line, = plot(x,sin(x))
for i in arange(1,200):
   line.set_ydata(sin(x+i/10.0))
   draw()

print 'FPS:' , 200/(time.time()-tstart)

fails with the backtrace:

$ python temp.py -dCocoaAgg
Traceback (most recent call last):
File "temp.py", line 2, in <module>
   from pylab import *
File "/opt/local/lib/python2.5/site-packages/pylab.py", line 1, in <module>
   from matplotlib.pylab import *
File "/opt/local/lib/python2.5/site-packages/matplotlib/pylab.py",
line 253, in <module>
   from matplotlib.pyplot import *
File "/opt/local/lib/python2.5/site-packages/matplotlib/pyplot.py",
line 75, in <module>
   new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/__init__.py",
line 25, in pylab_setup
   globals(),locals(),[backend_name])
File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_cocoaagg.py",
line 54, in <module>
   class FigureCanvasCocoaAgg(FigureCanvasAgg):
File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_cocoaagg.py",
line 63, in FigureCanvasCocoaAgg
   start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__
NameError: name 'FigureCanvasBase' is not defined

However this runs without issue using the MacOSX backend:

$ python temp.py -dMacOSX
FPS: 20.1183278689

Is there some missing dependency that could cause this?

Cheers

Adam

This looks like a simple bug in which FigureCanvasBase is not
imported. Try replacing line 31 in
matplotlib/backends/backend_cocoaagg.py with this::

    from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase

I've fixed the bug on the svn branch and trunk.

In a somewhat unrelated note, this style of "pylab animation" is no
longer encouraged or supported (and your example does not work with
cocoaagg, even with the fix, on my osx box). Rather, you should use
the GUI timeout or idle loop for your backend to support animation, as
in the examples in
http://matplotlib.sourceforge.net/examples/animation/index.html.
While there are no cocoa specific examples (feel free to contribute
one) the pattern should be fairly clear across the UIs we have
examples for.

JDH

···

On Wed, Jan 21, 2009 at 8:31 PM, Adam Mercer <ramercer@...287...> wrote:

Anyone?

Cheers

Adam

On Sat, Jan 17, 2009 at 17:19, Adam Mercer <ramercer@...287...> wrote:

Hi

I'm trying to track down an issue with the CocoaAgg backend on Mac OS
X using MacPorts, when run with the CocoaAgg backend the following
code:

from pylab import *
import time

ion()

tstart = time.time()
x = arange(0,2*pi,0.01)
line, = plot(x,sin(x))
for i in arange(1,200):
   line.set_ydata(sin(x+i/10.0))
   draw()

print 'FPS:' , 200/(time.time()-tstart)

fails with the backtrace:

$ python temp.py -dCocoaAgg
Traceback (most recent call last):
File "temp.py", line 2, in <module>
   from pylab import *
File "/opt/local/lib/python2.5/site-packages/pylab.py", line 1, in <module>
   from matplotlib.pylab import *
File "/opt/local/lib/python2.5/site-packages/matplotlib/pylab.py",
line 253, in <module>
   from matplotlib.pyplot import *
File "/opt/local/lib/python2.5/site-packages/matplotlib/pyplot.py",
line 75, in <module>
   new_figure_manager, draw_if_interactive, show = pylab_setup()
File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/__init__.py",
line 25, in pylab_setup
   globals(),locals(),[backend_name])
File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_cocoaagg.py",
line 54, in <module>
   class FigureCanvasCocoaAgg(FigureCanvasAgg):
File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_cocoaagg.py",
line 63, in FigureCanvasCocoaAgg
   start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__
NameError: name 'FigureCanvasBase' is not defined\

This looks like a simple bug in which FigureCanvasBase is not
imported. Try replacing line 31 in
matplotlib/backends/backend_cocoaagg.py with this::

   from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase

I've fixed the bug on the svn branch and trunk.

Thanks, that fixes the backtrace.

In a somewhat unrelated note, this style of "pylab animation" is no
longer encouraged or supported (and your example does not work with
cocoaagg, even with the fix, on my osx box). Rather, you should use
the GUI timeout or idle loop for your backend to support animation, as
in the examples in
http://matplotlib.sourceforge.net/examples/animation/index.html.
While there are no cocoa specific examples (feel free to contribute
one) the pattern should be fairly clear across the UIs we have
examples for.

Thanks, I'll pass that onto the user who reported this problem to me.

Cheers

Adam

···

On Wed, Jan 21, 2009 at 21:09, John Hunter <jdh2358@...287...> wrote: