Re: [Matplotlib-users] legend and bbox_to_anchor, and draggable()

2010-09-27 Thread Jae-Joon Lee
On Sun, Sep 26, 2010 at 4:11 AM, Jouni K. Seppänen  wrote:
> I'm not sure either. It seems that the two-number form of the bounding
> box is meant to create a degenerate bounding box so that any kind of
> location specifier ("upper right", "lower center", etc) will always hit
> that exact place, but perhaps naturally that makes it difficult to move
> the box around.
>

In the current implementation, the legend location (Legend.loc) is set
in the normalized coordinate of the bbox_to_anchor (and later
transformed to the "canvas coordinate" during the drawing time).

On the other hand, when the legend is moved by a user, it tries to
update Legend.loc from the current position of the legend in the
canvas coordinate, which results in NaNs if the bbox_to_anchor has
zero width and zero height. A workaround is to set the bbox_to_anchor
to its default value (Axes.bbox) when this happens. While I think it
is reasonable thing to do, let me know of any other opinion.

A patch is attached.
Unless there is no objection, I'll commit the patch soon.

Regards,

-JJ


fix_bbox_to_anchor_for_draggable_legend.diff
Description: Binary data
--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] legend and bbox_to_anchor, and draggable()

2010-09-25 Thread Jouni K . Seppänen
Daniel Hyams  writes:

> I was playing around with draggable legends, and some strange things started
> happening (exception down in the depths of beckend_agg.py, accompanied by a
> long stack trace).  To make a long story short, I can reproduce this in the
> draggable_legend.py example on the matplotlib website.  All you have to do
> is change line 7 [...] to
>
> l = ax.legend(bbox_to_anchor=(.1,.1))

Apparently this creates a bounding box with zero width and height, which
causes NaNs to appear in various transforms later on. It seems that you
can get the same placement of the legend with

l = ax.legend(bbox_to_anchor=(0,0,.1,.1))

which creates a non-degenerate bounding box that doesn't have this
problem. A possibly simpler option is

l = ax.legend(loc=(-0.2,0.1))

which sets the position of the lower-left corner of the legend box so
you'll need to tweak the coordinates from what you used with
bbox_to_anchor.

> I'm sure that I'm not understanding the proper usage of
> bbox_to_anchor.  

I'm not sure either. It seems that the two-number form of the bounding
box is meant to create a degenerate bounding box so that any kind of
location specifier ("upper right", "lower center", etc) will always hit
that exact place, but perhaps naturally that makes it difficult to move
the box around.

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] legend and bbox_to_anchor, and draggable()

2010-09-24 Thread Daniel Hyams
I was playing around with draggable legends, and some strange things started
happening (exception down in the depths of beckend_agg.py, accompanied by a
long stack trace).  To make a long story short, I can reproduce this in the
draggable_legend.py example on the matplotlib website.  All you have to do
is change line 7 from

l = ax.legend()

to

l = ax.legend(bbox_to_anchor=(.1,.1))

Fire this up, and move the legend box with your mouse.  It works.  Move
again, exception raised.

I'm sure that I'm not understanding the proper usage of bbox_to_anchor.  I
thought that i could use it to place the legend initially, and then let the
user drag the legend around if the placement wasn't satisfactory.

-- 
Daniel Hyams
dhy...@gmail.com
--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users