TypeError on CocoaAgg backend

OK, I'm having a bad backend day (insert joke here).

Since I am on OSX, I decided to switch over to the CocoaAgg backend,
but it fails when trying to show a histogram, yielding the following
TypeError:

In [4]: from matplotlib import use

In [5]: use('CocoaAgg')

In [6]: from pylab import hist, show

In [7]: from numpy import random

In [8]: x = random.exponential(2, 1000)

In [9]: hist(x)
Out[9]:
(array([545, 230, 117, 59, 18, 15, 11, 1, 3, 1]),
array([ 2.99606603e-03, 1.52977050e+00, 3.05654494e+00,
         4.58331937e+00, 6.11009381e+00, 7.63686824e+00,
         9.16364268e+00, 1.06904171e+01, 1.22171915e+01,
         1.37439660e+01]),
<a list of 10 Patch objects>)

In [10]: show()

···

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/Users/chris/Projects/Occupancy-abundance Manuscript/<ipython console>
in <module>()

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in show()
     44 def show():
     45 for manager in Gcf.get_all_fig_managers():
---> 46 manager.show()
     47
     48 def draw_if_interactive():

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in show(self)
    203 mplBundle,
    204 False)
--> 205 NSApplication.sharedApplication().run()
    206
    207

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in startWithBundle_(self, bundle)
    179 def startWithBundle_(self, bundle):
    180 #NSApplicationLoad()
--> 181 if not
bundle.loadNibFile_externalNameTable_withZone_('Matplotlib.nib', {},
None):
    182 print >>sys.stderr, 'Unable to load Matplotlib Cocoa UI!'
    183 sys.exit()

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in awakeFromNib(self)
     79
     80 self.plotView.setImageFrameStyle_(NSImageFrameGroove)
---> 81 self.plotView.image = NSImage.alloc().initWithSize_((0,0))
     82 self.plotView.setImage_(self.plotView.image)
     83

TypeError: cannot change a method

--
Christopher J. Fonnesbeck
+ Fish & Wildlife Research Institute (FWC)
+ 727.235.5570

Chris,

This error is due to more stringent error checking in pyobjc2 which
ships with Leopard. I was just preparing a patch to send to the
matplotlib dev guys, but if you replace all instances of self.image
with self._image in backend_cocoaagg.py, things should work. Because
PlotView is an NSImage subclass, it inherits a method named image.
pyobjc previously let you overwrite that method with a python instance
variable, but no longer, hence having to rename the instance variable.

barry

···

On Dec 3, 2007 3:38 PM, Chris Fonnesbeck <listservs@...935...> wrote:

OK, I'm having a bad backend day (insert joke here).

Since I am on OSX, I decided to switch over to the CocoaAgg backend,
but it fails when trying to show a histogram, yielding the following
TypeError:

In [4]: from matplotlib import use

In [5]: use('CocoaAgg')

In [6]: from pylab import hist, show

In [7]: from numpy import random

In [8]: x = random.exponential(2, 1000)

In [9]: hist(x)
Out[9]:
(array([545, 230, 117, 59, 18, 15, 11, 1, 3, 1]),
array([ 2.99606603e-03, 1.52977050e+00, 3.05654494e+00,
         4.58331937e+00, 6.11009381e+00, 7.63686824e+00,
         9.16364268e+00, 1.06904171e+01, 1.22171915e+01,
         1.37439660e+01]),
<a list of 10 Patch objects>)

In [10]: show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/Users/chris/Projects/Occupancy-abundance Manuscript/<ipython console>
in <module>()

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in show()
     44 def show():
     45 for manager in Gcf.get_all_fig_managers():
---> 46 manager.show()
     47
     48 def draw_if_interactive():

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in show(self)
    203 mplBundle,
    204 False)
--> 205 NSApplication.sharedApplication().run()
    206
    207

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in startWithBundle_(self, bundle)
    179 def startWithBundle_(self, bundle):
    180 #NSApplicationLoad()
--> 181 if not
bundle.loadNibFile_externalNameTable_withZone_('Matplotlib.nib', {},
None):
    182 print >>sys.stderr, 'Unable to load Matplotlib Cocoa UI!'
    183 sys.exit()

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in awakeFromNib(self)
     79
     80 self.plotView.setImageFrameStyle_(NSImageFrameGroove)
---> 81 self.plotView.image = NSImage.alloc().initWithSize_((0,0))
     82 self.plotView.setImage_(self.plotView.image)
     83

TypeError: cannot change a method

--
Christopher J. Fonnesbeck
+ Fish & Wildlife Research Institute (FWC)
+ 727.235.5570

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

sorry instances of self.plotView.image

···

On Dec 3, 2007 3:38 PM, Chris Fonnesbeck <listservs@...935...> wrote:

OK, I'm having a bad backend day (insert joke here).

Since I am on OSX, I decided to switch over to the CocoaAgg backend,
but it fails when trying to show a histogram, yielding the following
TypeError:

In [4]: from matplotlib import use

In [5]: use('CocoaAgg')

In [6]: from pylab import hist, show

In [7]: from numpy import random

In [8]: x = random.exponential(2, 1000)

In [9]: hist(x)
Out[9]:
(array([545, 230, 117, 59, 18, 15, 11, 1, 3, 1]),
array([ 2.99606603e-03, 1.52977050e+00, 3.05654494e+00,
         4.58331937e+00, 6.11009381e+00, 7.63686824e+00,
         9.16364268e+00, 1.06904171e+01, 1.22171915e+01,
         1.37439660e+01]),
<a list of 10 Patch objects>)

In [10]: show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/Users/chris/Projects/Occupancy-abundance Manuscript/<ipython console>
in <module>()

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in show()
     44 def show():
     45 for manager in Gcf.get_all_fig_managers():
---> 46 manager.show()
     47
     48 def draw_if_interactive():

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in show(self)
    203 mplBundle,
    204 False)
--> 205 NSApplication.sharedApplication().run()
    206
    207

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in startWithBundle_(self, bundle)
    179 def startWithBundle_(self, bundle):
    180 #NSApplicationLoad()
--> 181 if not
bundle.loadNibFile_externalNameTable_withZone_('Matplotlib.nib', {},
None):
    182 print >>sys.stderr, 'Unable to load Matplotlib Cocoa UI!'
    183 sys.exit()

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in awakeFromNib(self)
     79
     80 self.plotView.setImageFrameStyle_(NSImageFrameGroove)
---> 81 self.plotView.image = NSImage.alloc().initWithSize_((0,0))
     82 self.plotView.setImage_(self.plotView.image)
     83

TypeError: cannot change a method

--
Christopher J. Fonnesbeck
+ Fish & Wildlife Research Institute (FWC)
+ 727.235.5570

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I replaced the one instance of this that I found. I now get the following error:

In [7]: show()

···

On Dec 3, 2007 7:34 PM, Barry Wark <barrywark@...287...> wrote:

sorry instances of self.plotView.image

On Dec 3, 2007 3:38 PM, Chris Fonnesbeck <listservs@...935...> wrote:

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

/Users/chris/<ipython console> in <module>()

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in show()
     44 def show():
     45 for manager in Gcf.get_all_fig_managers():
---> 46 manager.show()
     47
     48 def draw_if_interactive():

/Library/Python/2.5/site-packages/matplotlib/backends/backend_cocoaagg.py
in show(self)
    203 mplBundle,
    204 False)
--> 205 NSApplication.sharedApplication().run()
    206
    207

ValueError: NSInvalidArgumentException - NSImageCell's object value
must be an NSImage.

--
Christopher J. Fonnesbeck
+ Fish & Wildlife Research Institute (FWC)
+ 727.235.5570

Chris,

I appologize for cryptic language and quickly written emails leading you astray. I've included the diff of backend_cocoaagg.py (which has also been sent to the mpl devs) which seems to work for me.

Barry

backend_cocoaagg.py.diff (1.72 KB)

I committed in r4571, presuming it is the same patch you sent before...

JDH

···

On Dec 5, 2007 12:36 PM, Barry Wark <barrywark@...287...> wrote:

Chris,

I appologize for cryptic language and quickly written emails leading
you astray. I've included the diff of backend_cocoaagg.py (which has
also been sent to the mpl devs) which seems to work for me.