On Sat, May 3, 2008 at 11:44 PM, Eric Bruning <[EMAIL PROTECTED]> wrote:

> The switch to/from raster mode was made in Axes.draw, where the artists for
> each axes are looped over. In the artist loop, I check if the artist to be
> rendered is listed in the draw_raster attribute on the renderer instance. If
> so, the appropriate calls are made to start and stop rasterizing.

Hi Eric,  thanks for the patch.  There are a couple of aspects of the
design here that I am not comfortable with, but I think with a few
changes this will be useful (though Michael, who implemented the mixed
mode renderer, will surely have important comments).  The primary
thing that bothers me is that one of the core aspects of the
matplotlib backend design is that the renderers know nothing about
artists -- artists know about renderers, but not the other way around.
 So I don't like using the renderer to store the rasterized artists.
It makes more sense to me for the artist to have has a property set
("set_rasterized" which could be True|False|None where None means "do
the default thing for the renderer").  Then you could do:

   if a.get_rasterized():
       renderer.start_rasterizing()
       a.draw(renderer)
       renderer.stop_rasterizing()
   else:
       a.draw(renderer)

Doing this in the axes.draw method may not be the most natural place
to do this since it could be done in the artist.draw method, but it
may be the most expedient.  This is an area where having support for
before_draw and  after_draw hooks might be useful. One potential
problem with either of these approached is it looks like the mixed
mode renderer is set up to handle multiple rasterized draws before
dumping the aggregate image into the backend on a stop_renderer, so
doing the start/stop in any of the approaches above would obviate this
efficiency.   The axes could aggregate the rasterized artists before
rendering and then do them all together, but making this play properly
with zorder will be tricky.  It does something like this already with
the "animated" artists so you may want to look at that.  For animated
artists in the current implementation, zorder is ignored (the animated
artists are drawn on top).  Chaco does something a bit more
sophisticated than this, since they have separate rendering levels and
buffers.

Another, less critical,  aspect of the patch that bothers me is
tagging the renderer with the undocumented attribute "draw_raster"
and then checking this with a hasattr in axes.draw.  python let's you
do this kind of stuff, and I've done plenty of it myself in
application building, but in my experience it makes for code that is
hard to maintain once the code base grows sufficiently large.
Although the mpl setters and getters are not the most pythonic
approach, they do make for code that is fairly readable and,
importantly, easily documented.

JDH

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to