From: Nicolas G. <hu...@ya...> - 2004-11-30 17:48:53
|
Hello, I have some question on the legend. the first is perhaps a bug: I was trying something like: plot([1,2,3],[2,3,4],label='toto') legend() I can't obtain a legend, instead I have an error message. So perhaps I didn't understand at all the message I obtain with: help(legend) (it's possible with my poor english :) ) or there are a problem. second things: I would like to have the box create by the legend commande behind my plot and not above because it hide some of the point. Perhaps another solution is to put the box bacground in "alpha mode" but I don't know how to do this. I will appreciate a lot your help, thanks. Nicolas Vous manquez despace pour stocker vos mails ? Yahoo! Mail vous offre GRATUITEMENT 100 Mo ! Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/ Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis. A télécharger gratuitement sur http://fr.messenger.yahoo.com |
From: Marek G. <mg...@gm...> - 2010-10-26 07:53:51
|
Dear All, I use hist in pylab.I have different sets of data in different colours in one chart. In legend all rectangulars are unfortunately blue. In plot() it is ok but not in hist(). How to receive correct colours in histogram legend? x is nested list x[1][2][3] is an ordinary list. for p in range(2,3): for c in range(0,4): hist(x[c][p][7],range=(0,2000),bins=20) title('Axis dist[m];nr '+str(p)+nams(x[3][p][7])) legend(['LHXGHX','>1','>3','>5']) figure() Best Regards Marek Giebułtowski |
From: Jae-Joon L. <lee...@gm...> - 2010-10-27 01:12:25
|
One option is to use proxy artists. http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist Regards, -JJ 2010/10/26 Marek Giebułtowski <mg...@gm...>: > Dear All, > I use hist in pylab.I have different sets of data in different colours > in one chart. In legend all rectangulars are unfortunately blue. > In plot() it is ok but not in hist(). > How to receive correct colours in histogram legend? > > x is nested list x[1][2][3] is an ordinary list. > for p in range(2,3): > for c in range(0,4): > hist(x[c][p][7],range=(0,2000),bins=20) > title('Axis dist[m];nr '+str(p)+nams(x[3][p][7])) > legend(['LHXGHX','>1','>3','>5']) > figure() > Best Regards > Marek Giebułtowski > > ------------------------------------------------------------------------------ > Nokia and AT&T present the 2010 Calling All Innovators-North America contest > Create new apps & games for the Nokia N8 for consumers in U.S. and Canada > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store > http://p.sf.net/sfu/nokia-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
From: John H. <jdh...@ac...> - 2004-11-30 20:57:36
|
>>>>> "Nicolas" == Nicolas Gruel <hu...@ya...> writes: Nicolas> Hello, I have some question on the legend. Nicolas> the first is perhaps a bug: Nicolas> I was trying something like: Nicolas> plot([1,2,3],[2,3,4],label='toto') legend() Nicolas> I can't obtain a legend, instead I have an error Nicolas> message. So perhaps I didn't understand at all the Nicolas> message I obtain with: help(legend) (it's possible with Nicolas> my poor english :) ) or there are a problem. Yep, it's a bug. Replace the indicate line from axes.py loc = kwargs.gry('loc', 1) with loc = kwargs.get('loc', 1) ^^^ Note to self: run pychecker more often. Nicolas> second things: I would like to have the box create by the Nicolas> legend commande behind my plot and not above because it Nicolas> hide some of the point. Perhaps another solution is to Nicolas> put the box bacground in "alpha mode" but I don't know Nicolas> how to do this. http://sourceforge.net/mailarchive/forum.php?thread_id=6039503&forum_id=33405 JDH |
From: Humufr <hu...@ya...> - 2004-12-01 14:34:55
|
Hi John, I tried: > Yep, it's a bug. Replace the indicate line from > axes.py > > loc = kwargs.gry('loc', 1) > > with > > loc = kwargs.get('loc', 1) > ^^^ That correct the problem with legend() but I have another problem and I think it's another bug (not sure) it's not possible to tell to matplotlib in this case o use the "loc" keywords more it's impossible to use this keywords. There are always an error message: File "<string>", line 3, in legend File "/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 1502, in legend self.legend_ = Legend(self, lines, labels, loc, **kwargs) TypeError: __init__() got multiple values for keyword argument 'loc' example: plot ([2,3],[4,5]) legend(('toto'),loc=2) I tried everything: loc='upper left', loc=0,1 , loc=(0,1), loc=2 etc. Nothing work but if I omit the " loc= " . It's ok and that explain probably why I cant do something like: plot([1,2],[4,5],label='toto') legend(loc='upper left') Another strange thing I remark is: if you are doing: plot([1,2],[4,5]) legend(('toto')) the text for the legend is vertical and not horizontal, that's work normally when we are using more than one argument. Thank you very much for you fast answer and sorry for the second question I had to verify more precisely in the archival. Nicolas |
From: Jochen V. <vo...@se...> - 2004-12-01 14:45:15
|
Hello Nicolas On Wed, Dec 01, 2004 at 09:34:51AM -0500, Humufr wrote: > Another strange thing I remark is: >=20 > if you are doing: >=20 > plot([1,2],[4,5]) > legend(('toto')) >=20 > the text for the legend is vertical and not horizontal, that's work=20 > normally when we are using more than one argument. This happens because ('toto') is not a one-element list but a string. If you write plot([1,2],[4,5]) legend(('toto',)) instead it works as expected. I hope this helps, Jochen --=20 http://seehuhn.de/ |
From: John H. <jdh...@ac...> - 2004-12-01 14:56:02
|
>>>>> "Jochen" == Jochen Voss <vo...@se...> writes: Jochen> Hello Nicolas Jochen> On Wed, Dec 01, 2004 at 09:34:51AM -0500, Humufr wrote: >> Another strange thing I remark is: >> >> if you are doing: >> >> plot([1,2],[4,5]) legend(('toto')) >> >> the text for the legend is vertical and not horizontal, that's >> work normally when we are using more than one argument. Jochen> This happens because ('toto') is not a one-element list Jochen> but a string. If you write Jochen> plot([1,2],[4,5]) legend(('toto',)) Jochen> instead it works as expected. This is such a common mistake I think we should special case string input for the labels and make it a len(1) tuple if is_string_like(labels): labels = (labels, ) All opposed, say nay! JDH |
From: Humufr <hu...@ya...> - 2004-12-01 19:43:27
|
Hi John, I just recuperate the cvs and I saw that you correct a lot of things inside the legend, thanks very much. you will hate me soon I think :) but I found one bug and onething I don't like too much: 1) the bug: I tried: plot([1,2],[4,5],'g^',markersize=4,label='1') errorbar([1,4],[6,7],[1,1],fmt='bh',markersize=4,label='4') #plot([3,4],[6,7]) legend() show() and there are a problem with errorbar and the label and the legend. Different line appeard and at the end we have only the good symbols) 2) I add the line: plot([3,4],[6,7]) only to show you that even if the plot command doesn't have a label the legend give a place for it. I think at two solution to solve this (perhaps it's already implemented and I didn't find...): - by default if there are some label with the plot command the plot command without are not take in count to create the legend - add something like: label=None to indicate the the user don't want this line in the legend. Thanks again to have found and correct all this bug so fast, I'm very impressed :) Nicolas |
From: John H. <jdh...@ac...> - 2004-12-01 21:15:21
|
>>>>> "Humufr" == Humufr <hu...@ya...> writes: Humufr> the bug: Humufr> I tried: Humufr> plot([1,2],[4,5],'g^',markersize=4,label='1') Humufr> errorbar([1,4],[6,7],[1,1],fmt='bh',markersize=4,label='4') Humufr> #plot([3,4],[6,7]) Humufr> legend() Humufr> show() Humufr> and there are a problem with errorbar and the label and Humufr> the legend. Different line appeard and at the end we have Humufr> only the good symbols) I don't consider this a bug but maybe you can convince me :-). Legend tries to be helpful but not omniscient. If you have many lines and only want to include some of them in the legend, just use the explicit legend(lines, labels) form from matplotlib.matlab import * l1, = plot([1,2],[4,5],'g^',markersize=4) l2, errlines = errorbar([1,4],[6,7],[1,1],fmt='bh',markersize=4) plot([3,4],[6,7]) legend((l1, l2), ('1', '4')) show() Your suggestion that the legend ignore lines with empty labels appears reasonable at first glance, but as Norbert will tell you, some people use the fact that matplotlib legends include lines with empty labels to their advantage when laying out legends. So in this case there is a way to get matplotlib to make the legend you want, and if legend tries to get too smart about guessing what you want it will get in the way of power users who don't what matplotlib guessing what they are trying to do. Humufr> 2) Humufr> I add the line: plot([3,4],[6,7]) only to show you that Humufr> even if the plot command doesn't have a label the legend Humufr> give a place for it. I think at two solution to solve this Humufr> (perhaps it's already implemented and I didn't find...): Humufr> - by default if there are some label with the plot command Humufr> the plot command without are not take in count to create Humufr> the legend Humufr> - add something like: label=None to indicate the the user Humufr> don't want this line in the legend. This could work. Currently the default label is '', which as I said is a perfectly legitimate label in some cases. We could use None as a hint to legend. It would increase the coding burden somewhat, since we'd always have to check for None before performing string ops on the legend. I'm amenable to this approach. Anyone else have input here? Humufr> Thanks again to have found and correct all this bug so Humufr> fast, I'm very impressed :) Thanks! JDH |
From: Norbert N. <Nor...@gm...> - 2004-12-01 19:54:22
|
Hi there, apart from the "gry"-typo, the currect CVS-code really is in a broken state after my patch was applied and half-way reverted back. (The python2.2-pop problem) Possible solutions: * change "kwargs.get('xxx',def)" to "popd(kwargs,'xxx',def)" and add popd to the import from cbook * change "kwargs.get('xxx',def)" to "kwargs.pop('xxx',def)" (will not work for Python 2.2 * change the last lines of Axes.legend according to: lines = flatten(lines) + kwargs["loc"] = loc + self.legend_ = Legend(self, lines, labels, **kwargs) - self.legend_ = Legend(self, lines, labels, loc, **kwargs) return self.legend_ I guess, the first solution is, what will be done in the long run. Ciao, Nobbi Am Mittwoch, 1. Dezember 2004 15:34 schrieb Humufr: > Hi John, > > I tried: > > Yep, it's a bug. Replace the indicate line from > > axes.py > > > > loc = kwargs.gry('loc', 1) > > > > with > > > > loc = kwargs.get('loc', 1) > > ^^^ > > That correct the problem with legend() but I have another problem and I > think it's another bug (not sure) it's not possible to tell to > matplotlib in this case o use the "loc" keywords more it's impossible to > use this keywords. There are always an error message: > File "<string>", line 3, in legend > File "/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 1502, > in legend > self.legend_ = Legend(self, lines, labels, loc, **kwargs) > TypeError: __init__() got multiple values for keyword argument 'loc' > > > example: > > plot ([2,3],[4,5]) > legend(('toto'),loc=2) > > I tried everything: loc='upper left', loc=0,1 , loc=(0,1), loc=2 etc. > Nothing work but if I omit the " loc= " . It's ok and that explain > probably why I cant do something like: > > plot([1,2],[4,5],label='toto') > legend(loc='upper left') > > > Another strange thing I remark is: > > if you are doing: > > plot([1,2],[4,5]) > legend(('toto')) > > the text for the legend is vertical and not horizontal, that's work > normally when we are using more than one argument. > > Thank you very much for you fast answer and sorry for the second > question I had to verify more precisely in the archival. > > > Nicolas > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://productguide.itmanagersjournal.com/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- _________________________________________Norbert Nemec Bernhardstr. 2 ... D-93053 Regensburg Tel: 0941 - 2009638 ... Mobil: 0179 - 7475199 eMail: <No...@Ne...> |
From: John H. <jdh...@ac...> - 2004-12-01 21:01:33
|
>>>>> "Norbert" == Norbert Nemec <Nor...@gm...> writes: Norbert> Hi there, apart from the "gry"-typo, the currect CVS-code Norbert> really is in a broken state after my patch was applied Norbert> and half-way reverted back. (The python2.2-pop problem) Norbert> Possible solutions: Norbert> * change "kwargs.get('xxx',def)" to Norbert> "popd(kwargs,'xxx',def)" and add popd to the import from Norbert> cbook Here is what I committed to CVS earlier today in axes.Axes.legend if len(args)==0: labels = [line.get_label() for line in self.lines] lines = self.lines loc = popd(kwargs, 'loc', 1) and more like it. I think this works... JDH |