Ah, that makes more sense Jae-Joon - thanks!

With this addition it all looks fine to me - I've attached a patch
against 6174 that does everything I'd like to see it do... note that
I've left in the TODO in collections.py simply because I still am not
certain that what I'm doing there is correct in all use-cases...

On Mon, Oct 6, 2008 at 11:22 PM, Jae-Joon Lee <[EMAIL PROTECTED]> wrote:
> Hi Eric,
>
> As far as I know, get_window_extent is meant to return the extent of
> the object in the display coordinate. And, as you may have noticed,
> often this is used to calculate the relative position of  objects.
>
> I quickly went through your patch and my guess is your implementation
> of get_window_extent is correct in this regard, but I haven't
> considered this seriously so I may be wrong.
>
> On the other hand, I guess the original problem you had is not related
> with the get_window_extents() method.
> The legend class has a _update_positions() method  which is called
> before the legends are drawn. And you have to update positions of your
> handles within this method.
>
> In the simple patch below. I tried to implement some basic update code
> for the polycollections ( I also slightly adjusted the y-offsets. This
> is just my personal preference). See if this patch works for you.
>
> Regards,
>
> -JJ
>
>
>
> Index: lib/matplotlib/legend.py
> ===================================================================
> --- lib/matplotlib/legend.py    (revision 6163)
> +++ lib/matplotlib/legend.py    (working copy)
> @@ -532,6 +540,12 @@
>             elif isinstance(handle, Rectangle):
>                 handle.set_y(y+1/4*h)
>                 handle.set_height(h/2)
> +            elif isinstance(handle, RegularPolyCollection):
> +                offsets = handle.get_offsets()
> +                xvals = [x for (x, _) in offsets]
> +                yy = y + h
> +                yvals=[yy-4./8*h,yy-3./8*h,yy-4./8*h]
> +                handle.set_offsets(zip(xvals, yvals))
>
>         # Set the data for the legend patch
>         bbox = self._get_handle_text_bbox(renderer)
>
>
>
> On Tue, Oct 7, 2008 at 12:15 AM, Erik Tollerud <[EMAIL PROTECTED]> wrote:
>> Does anyone have anything new here? I'm perfectly willing to
>> experiment, but I'm really at a loss as to what
>> get_window_extent(self,render) is supposed to do (clearly get some
>> window extent, but exactly what window and what coordinates the extent
>> is in is what is confusing me).
>>
>> On Tue, Sep 23, 2008 at 11:41 AM, John Hunter <[EMAIL PROTECTED]> wrote:
>>> On Tue, Sep 23, 2008 at 12:20 AM, Erik Tollerud <[EMAIL PROTECTED]> wrote:
>>>> Attached is a diff against revision 6115 that contains a patch to
>>>> improve the behavior of the legend function when showing legends for
>>>
>>> Erik,
>>>
>>> I haven't had a chance to get to this yet.  Could you please also post
>>> it on the sf patch tracker so it doesn't get dropped, and ping us with
>>> a reminder in a few days if nothing has happened....
>>>
>>> JDH
>>>
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
>> Build the coolest Linux based applications with Moblin SDK & win great prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> Matplotlib-devel mailing list
>> Matplotlib-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>>
>



-- 
Erik Tollerud
Graduate Student
Center For Cosmology
Department of Physics and Astronomy
2142 Frederick Reines Hall
University of California, Irvine
Office Phone: (949)824-2587
Cell: (651)307-9409
[EMAIL PROTECTED]
Index: lib/matplotlib/legend.py
===================================================================
--- lib/matplotlib/legend.py	(revision 6174)
+++ lib/matplotlib/legend.py	(working copy)
@@ -306,18 +306,26 @@
                 ret.append(legline)
 
             elif isinstance(handle, RegularPolyCollection):
-                if self.numpoints == 1:
-                    xdata = np.array([left])
-                p = Rectangle(xy=(min(xdata), y-3/4*HEIGHT),
-                              width = self.handlelen, height=HEIGHT/2,
-                              )
-                p.set_facecolor(handle._facecolors[0])
-                if handle._edgecolors != 'none' and len(handle._edgecolors):
-                    p.set_edgecolor(handle._edgecolors[0])
-                self._set_artist_props(p)
-                p.set_clip_box(None)
-                p.set_clip_path(None)
-                ret.append(p)
+                xvals=[min(xdata),min(xdata)+self.handlelen/2,min(xdata)+self.handlelen]
+                yvals=[y-3/4*HEIGHT,y-1/4*HEIGHT,y-3/4*HEIGHT]
+                nverts=handle.get_paths()[0].vertices.shape[0]-1
+                szs=[min(handle._sizes),max(handle._sizes)]
+                szs.insert(1,(szs[0]+szs[1])/2)
+                rpc = RegularPolyCollection(nverts,
+                    offsets=zip(xvals,yvals),
+                    transOffset=self.get_transform(),
+                    edgecolors=handle.get_edgecolors(),
+                    linewidth=handle.get_linewidth(),
+                    sizes=szs,
+                    rotation=handle._rotation)
+                if handle.get_array() is None:
+                    rpc.set_facecolors(handle.get_facecolors())
+                else:
+                    rpc.set_array(np.array([0,0.5,1]))
+                    rpc.set_cmap(handle.cmap)
+                    rpc.set_norm(handle.norm)
+                rpc.set_figure(self.figure)
+                ret.append(rpc)
 
             else:
                 ret.append(None)
@@ -532,6 +540,12 @@
             elif isinstance(handle, Rectangle):
                 handle.set_y(y+1/4*h)
                 handle.set_height(h/2)
+            elif isinstance(handle,RegularPolyCollection):
+                offsets = handle.get_offsets()
+                xvals = [x for (x, _) in offsets]
+                yy = y + h
+                yvals=[yy-4./8*h,yy-3./8*h,yy-4./8*h]
+                handle.set_offsets(zip(xvals, yvals))
 
         # Set the data for the legend patch
         bbox = self._get_handle_text_bbox(renderer)
Index: lib/matplotlib/collections.py
===================================================================
--- lib/matplotlib/collections.py	(revision 6174)
+++ lib/matplotlib/collections.py	(working copy)
@@ -147,6 +147,12 @@
             offsets, transOffset.frozen())
         result = result.inverse_transformed(transData)
         return result
+        
+    def get_window_extent(self, renderer):
+        bbox = self.get_datalim(transforms.IdentityTransform())
+        #TODO:check to ensure that this does not fail for
+        #cases other than scatter plot legend
+        return bbox
 
     def _prepare_points(self):
         """Point prep for drawing and hit testing"""
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to