Fwd: Re: [Matplotlib-users] wxPython Phoenix - backend_wxagg

1 view
Skip to first unread message

Werner

unread,
Apr 26, 2013, 9:01:30 AM4/26/13
to wxpyth...@googlegroups.com
Hi Robin,

The problem for me was on Python 2.7.2, so is there maybe an problem that wx doesn't recognize the Python buffer object?

Werner


-------- Original Message --------
Subject: Re: [Matplotlib-users] wxPython Phoenix - backend_wxagg
Date: Fri, 26 Apr 2013 08:40:55 -0400
From: Michael Droettboom <md...@stsci.edu>
To: <matplotl...@lists.sourceforge.net>


On 04/26/2013 02:57 AM, Werner F. Bruhin wrote:
> Hi,
>
> Anyone can provide some info on what "agg.buffer_rgba" returns and maybe
> even some suggestion on how to resolve this issue in the wxagg backend.

It returns a Python buffer object on Python 2, though on Python 3 it is 
a memoryview, since buffer was deprecated.  Perhaps wx is also doing 
something different depending on the version of Python.
>
> Thanks
> Werner
>
> P.S.
> The archive on Sourceforge for this list stops in June 2012, noticed
> this as I wanted to check if there are answers I didn't get for some reason.
> http://sourceforge.net/mailarchive/forum.php?forum_name=matplotlib-users

Yeah -- I've reported that to sourceforge many times.  Not sure what the 
issue is.  Personally, I use gmane when I need to search the archive and 
it works rather well.

Mike

>
> On 20/04/2013 08:58, Werner F. Bruhin wrote:
>> Hi,
>>
>> I am trying to get matplotlib 1.2.0 to work with wxPython Phoenix - will
>> provide a patch when it is working.
>>
>> Made the changes to backend_wx* for things like EmptyImage/EmptyBitmap
>> and Toolbar but I am stuck on the following.
>>
>>        if bbox is None:
>>            # agg => rgba buffer -> bitmap
>>            if 'phoenix' in wx.PlatformInfo:
>>                return wx.Bitmap.FromBufferRGBA(int(agg.width),
>> int(agg.height),
>> memoryview(agg.buffer_rgba()))
>>            else:
>>                return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
>>                                               agg.buffer_rgba())
>>        else:
>>            # agg => rgba buffer -> bitmap => clipped bitmap
>>            return _WX28_clipped_agg_as_bitmap(agg, bbox)
>>
>> TypeError: cannot make memory view because object does not have the
>> buffer interface
>> File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 63, in
>> <module>
>>      demo()
>> File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 60, in demo
>>      app.MainLoop()
>> File "c:\Python27\Lib\site-packages\wx-2.9.6-msw-phoenix\wx\core.py",
>> line 1841, in MainLoop
>>      rv = wx.PyApp.MainLoop(self)
>> File "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py",
>> line 1209, in _onPaint
>>      self.draw(drawDC=drawDC)
>> File
>> "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wxagg.py",
>> line 61, in draw
>>      self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
>> File
>> "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wxagg.py",
>> line 173, in _convert_agg_to_wx_bitmap
>>      memoryview(agg.buffer_rgba()))
>>
>> I tried using "memoryview" based on a suggestion by Robin Dunn, and
>> based on the following info I see in the debugger that should work no?
>>
>> agg.buffer_rgba()
>> <read-write buffer ptr 0x05400638, size 229200 at 0x055FC680>
>> type(agg.buffer_rgba())
>> <type 'buffer'>
>> agg
>> <matplotlib.backends.backend_agg.RendererAgg instance at 0x04BA0670>
>>
>> If I don't use "memoryview" (which would probably be preferred) I get
>> the following exception.
>>
>> Can someone help us figure this one out.
>>
>> Thanks
>> Werner
>>
>>
>> TypeError: Bitmap.FromBufferRGBA(): argument 3 has unexpected type 'buffer'
>> File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 63, in
>> <module>
>>      demo()
>> File "h:\devProjectsT\aaTests\matplotlib\wxembedding-5.py", line 60, in demo
>>      app.MainLoop()
>> File "c:\Python27\Lib\site-packages\wx-2.9.6-msw-phoenix\wx\core.py",
>> line 1841, in MainLoop
>>      rv = wx.PyApp.MainLoop(self)
>> File "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wx.py",
>> line 1209, in _onPaint
>>      self.draw(drawDC=drawDC)
>> File
>> "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wxagg.py",
>> line 61, in draw
>>      self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
>> File
>> "c:\Python27\Lib\site-packages\matplotlib\backends\backend_wxagg.py",
>> line 173, in _convert_agg_to_wx_bitmap
>>      agg.buffer_rgba())
>>
>> ------------------------------------------------------------------------------
>> Precog is a next-generation analytics platform capable of advanced
>> analytics on semi-structured data. The platform includes APIs for building
>> apps and a phenomenal toolset for data science. Developers can use
>> our toolset for easy data analysis & visualization. Get a free account!
>> http://www2.precog.com/precogplatform/slashdotnewsletter
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotl...@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
> ------------------------------------------------------------------------------
> Try New Relic Now & We'll Send You this Cool Shirt
> New Relic is the only SaaS-based application performance monitoring service
> that delivers powerful full stack analytics. Optimize and monitor your
> browser, app, & servers with just a few lines of code. Try New Relic
> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
> _______________________________________________
> Matplotlib-users mailing list
> Matplotl...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Matplotlib-users mailing list
Matplotl...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users




Robin Dunn

unread,
Apr 26, 2013, 10:59:09 PM4/26/13
to wxPyth...@googlegroups.com
Werner wrote:
> Hi Robin,
>
> The problem for me was on Python 2.7.2, so is there maybe an problem
> that wx doesn't recognize the Python buffer object?
>

The new buffer APIs go as far back as 2.6, IIRC, and the memoryview and
bytearray object types are available in 2.7 in addition to 3.x and that
I what I'm using in Phoenix. I would have expected MPL to do so also
since numpy is an integral part of MPL and the new buffer interface was
basically designed for and by numpy...

Anyway, while double checking all this I realized that it would not be
hard for me to accept old or new buffer objects for source buffers (I'll
still use memoryviews or bytearrays when on the producer side of things)
so try again after the next snapshot build. My unittests with
array.arrrays started working after the change so I expect that MPL's
rgba buffer should work too.


--
Robin Dunn
Software Craftsman
http://wxPython.org
Reply all
Reply to author
Forward
0 new messages