SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Christian M. <mee...@un...> - 2005年09月30日 09:21:01
Hi,
I'm looping over a list like this 
['name',[data_array],'name2',[data_array2],...] like this:
for x,y in zip(toplot_list,linestyles):
 if type(x) == type(array([])):
 pylab.plot(wavelengths,x,'k%s'% y)
 pylab.legend(toplot_list[toplot_list.index(x)-1])
Now there is a problem with the legend, that I don't see all names, but 
only the last. I seems to me like the names get superposed, though I 
cannot see this. Anyway, if I have a name like 'hello' the entry in the 
legend looks like:
h
e
l
l
o
Well, this is not quite the behaviour I wanted.
Does anybody know how to increase the size of the legend automatically 
so that all names can be written out? Or is it possible to prevent line 
break somehow?
TIA
Christian
From: John H. <jdh...@ac...> - 2005年09月30日 13:39:10
>>>>> "Christian" == Christian Meesters <mee...@un...> writes:
 Christian> Hi, I'm looping over a list like this
 Christian> ['name',[data_array],'name2',[data_array2],...] like
 Christian> this:
 Christian> for x,y in zip(toplot_list,linestyles): if type(x) ==
 Christian> type(array([])): pylab.plot(wavelengths,x,'k%s'% y)
 Christian> pylab.legend(toplot_list[toplot_list.index(x)-1])
 Christian> Now there is a problem with the legend, that I don't
 Christian> see all names, but only the last. I seems to me like
 Christian> the names get superposed, though I cannot see
 Christian> this. Anyway, if I have a name like 'hello' the entry
 Christian> in the legend looks like: h e l l o Well, this is not
 Christian> quite the behaviour I wanted. Does anybody know how to
 Christian> increase the size of the legend automatically so that
 Christian> all names can be written out? Or is it possible to
 Christian> prevent line break somehow?
Call the legend outside the list with a list of lines and labels you
want to pass to it. The strange 'hello' artifact you are seeing is
because 'hello' is a string and the legend code is iterating over it. 
Something like
lines = []
labels = []
for val in something:
 lines.extend(plot(val))
 labels.append(somelabel)
legend(lines, labels)
Or using autolegend
for val in something:
 plot(val, label=somelabel)
legend()
JDH
From: Paul B. <peb...@gm...> - 2005年09月30日 14:55:35
John,
Since this appears to be a recurrent problem, would it not be better to tes=
t
for a string and then not do the iteration. In other words, the iteration
should be done only for lists and tuples.
-- Paul
On 9/30/05, John Hunter <jdh...@ac...> wrote:
>
> >>>>> "Christian" =3D=3D Christian Meesters <mee...@un...> write=
s:
>
> Christian> Hi, I'm looping over a list like this
> Christian> ['name',[data_array],'name2',[data_array2],...] like
> Christian> this:
>
> Christian> for x,y in zip(toplot_list,linestyles): if type(x) =3D=3D
> Christian> type(array([])): pylab.plot(wavelengths,x,'k%s'% y)
> Christian> pylab.legend(toplot_list[toplot_list.index(x)-1])
>
> Christian> Now there is a problem with the legend, that I don't
> Christian> see all names, but only the last. I seems to me like
> Christian> the names get superposed, though I cannot see
> Christian> this. Anyway, if I have a name like 'hello' the entry
> Christian> in the legend looks like: h e l l o Well, this is not
> Christian> quite the behaviour I wanted. Does anybody know how to
> Christian> increase the size of the legend automatically so that
> Christian> all names can be written out? Or is it possible to
> Christian> prevent line break somehow?
>
> Call the legend outside the list with a list of lines and labels you
> want to pass to it. The strange 'hello' artifact you are seeing is
> because 'hello' is a string and the legend code is iterating over it.
>
> Something like
>
> lines =3D []
> labels =3D []
> for val in something:
> lines.extend(plot(val))
> labels.append(somelabel)
> legend(lines, labels)
>
>
> Or using autolegend
> for val in something:
> plot(val, label=3Dsomelabel)
> legend()
>
>
> JDH
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Christian M. <mee...@un...> - 2005年09月30日 14:03:45
Thanks John, works great.
> Since this appears to be a recurrent problem, would it not be better 
> to test for a string and then not do the iteration. In other words, 
> the iteration should be done only for lists and tuples.
Well Paul, I guess this is my fault, I should have known better by 
know. But I actually think you are right: Since its not really self 
explaining and people are making the same mistake over and over again 
(me even twice, arrgh!), it's worth to consider your idea.
Cheers,
Christian
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /