[IPython-User] Subplot legend not working on embedded plots?
Matthias BUSSONNIER
bussonniermatthias@gmail....
Wed Jul 25 13:52:45 CDT 2012
Le 25 juil. 2012 à 20:43, Adam Hughes a écrit :
> Oops.
>
> Sorry Matthias, I'm being sloppy. I didn't mention that although I'm passing a 1-d array for x, I'm actually passing a multi-dimensional array for y. In fact, I'm just passing a pandas dataframe object. Therefore, if I have a dataframe of 6 lines for example, when I do ax.plot(x,y) I get 6 plots out. What I'd like to do is pass the labels of all six of these lines in as well in the form of a list.
I'll also ask on Pandas ML, is I remember SciPy correctly Wes showed that there where some way of intelligent plotting with panda.
And I guess it might also be a wish list on MPL if it is not implemented.
--
Matthias
>
> I didn't realize this until your example, but I suppose I could just plot the lines one at a time and pass in the labels in each iteration. For example:
>
> for i in y:
> ax.plot(x, y[i], label=index[i])
> But there has to be a way to just pass a list of labels into a multilineplot all at once. I realize now that my issue is now with pyplot and not with IPython, so thanks for your help!
>
> On Wed, Jul 25, 2012 at 2:38 PM, Matthias BUSSONNIER <bussonniermatthias@gmail.com> wrote:
>
> Le 25 juil. 2012 à 20:29, Adam Hughes a écrit :
>
> > Thanks.
> >
> > That does work correctly for me; however, is printing the string "mydata" for the name of each line.
> ... i'm not quite sure I understand what you want to do...
>
> fig, ax=plt.subplots(1, figsize=(5,5) )
>
> x,y = range(10),range(10)
> ax.plot(x,y,label='mydata')
>
> x,y = range(0,10),range(1,11)
> ax.plot(x,y,label='mydata2')
>
> x,y = range(0,10),range(2,12)
> ax.plot(x,y,label='mydata3')
>
> ax.legend()
>
> give me 3 different labels
> --
> Matthias
>
> > Do you know offhand how to get it to understand a list of strings? I'll look through the matplotlib docs further.
> >
> > On Wed, Jul 25, 2012 at 2:19 PM, Matthias BUSSONNIER <bussonniermatthias@gmail.com> wrote:
> >
> > Le 25 juil. 2012 à 20:14, Adam Hughes a écrit :
> >
> > > Hi,
> > >
> > > I'm using notebook with inline plots:
> > >
> > > ipython notebook --pylab inline
> > >
> > > And noticed that if I create a subplot, then try to add a legend using ax.legend(), the legend doesn't appear.
> > >
> > > something like:
> > >
> > > fig, ax=plt.subplots(1, figsize=(12,12) )
> > > ax.plot(x,y)
> > > ax.legend()
> >
> > By setting a label in plot(), this works for me :
> >
> > fig, ax=plt.subplots(1, figsize=(5,5) )
> > x,y = range(10),range(10)
> > ax.plot(x,y,label='mydata')
> > ax.legend()
> >
> > --
> > Matthias
> >
> > >
> > >
> > > Am I doing something incorrectly or is this a known bug?
> > > _______________________________________________
> > > IPython-User mailing list
> > > IPython-User@scipy.org
> > > http://mail.scipy.org/mailman/listinfo/ipython-user
> >
> > _______________________________________________
> > IPython-User mailing list
> > IPython-User@scipy.org
> > http://mail.scipy.org/mailman/listinfo/ipython-user
> >
> > _______________________________________________
> > IPython-User mailing list
> > IPython-User@scipy.org
> > http://mail.scipy.org/mailman/listinfo/ipython-user
>
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
More information about the IPython-User
mailing list