Try something like

handles1, labels1 = ax1.get_legend_handles_labels()
handles2, labels2 = ax2.get_legend_handles_labels()
ax2.legend(handles1+handles2, labels1+labels2)

Also, see

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

Regards,

-JJ


On Sat, Sep 25, 2010 at 6:08 AM, Raju Subban <rajusubba...@gmail.com> wrote:
> Hi,
> In the code below legend(label) for ax2 is shown as ax2.legend() is called
> after ax1.legend().
> Both plots do show up as expected.
>
> What should I do to get the legends for both plots.
>
> Thank you
> Raju
> --------------------------------------
> import matplotlib.pyplot as plt
> import numpy as py
> x=np.arange(0.0,np.e,0.02)
> y1=np.exp(-x)
> y2=np.exp(x)
> fig = plt.figure()
> ax1=fig.add_subplot(111)
> ax2=ax1.twinx()
> ax1.plot(x,y1,label="First")
> ax2.plot(x,y2,label="Second")
> ax1.legend()
> ax2.legend()
> plt.show()
>
> --
> Hemantharaju Subbanna
> 408-857-9414(cell)
>
> ------------------------------------------------------------------------------
> 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
>
>

------------------------------------------------------------------------------
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

Reply via email to