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 |