On Tue, Sep 7, 2010 at 11:04 AM, Paul Ivanov <pivanov...@gmail.com> wrote:
> Is this a reasonable way of achieving the desired result?
>

Yes.
You may take a look at the legend guide.

http://matplotlib.sourceforge.net/users/legend_guide.html

For your original question, it is not possible to do that with the
current legend implementation. However, you may put the legend inside
the AnnotationBbox, which enables this. I'm posting the example for
any future reference.

Regards,

-JJ

# small example
ax = plt.subplot(1,1,1)
ax.plot([0,1], label='ax1')

leg = ax.legend()
ax.legend_ = None # remove the legend from the axes.

ax2 = ax.twinx()
ax2.plot([1,0], 'r--',label='ax2')
leg2 = ax2.legend() # create a legend


# add leg as AnnotationBbox
from matplotlib.offsetbox import AnnotationBbox

leg3 = AnnotationBbox(leg._legend_box, (0, 1),
                      xybox=(-5, 0),
                      xycoords=leg2.legendPatch,
                      boxcoords="offset points",
                      box_alignment=(1., 1.), pad=0,
                      )
# adjust zorder so that leg3 is drawn after leg2
leg3.zorder = leg2.zorder+0.1

ax2.add_artist(leg3)

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to