From: <mme...@us...> - 2008-12-12 13:03:10
|
Revision: 6583 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6583&view=rev Author: mmetz_bn Date: 2008-12-12 13:03:04 +0000 (Fri, 12 Dec 2008) Log Message: ----------- labels for multiple data histograms Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/axes.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-12-12 12:58:46 UTC (rev 6582) +++ trunk/matplotlib/CHANGELOG 2008-12-12 13:03:04 UTC (rev 6583) @@ -1,3 +1,6 @@ +2008-12-12 Added support to asign labels to histograms of multiple + data. - MM + ================================================================= 2008-12-11 Released 0.98.5 at svn r6573 Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2008-12-12 12:58:46 UTC (rev 6582) +++ trunk/matplotlib/lib/matplotlib/axes.py 2008-12-12 13:03:04 UTC (rev 6583) @@ -29,6 +29,7 @@ iterable = cbook.iterable is_string_like = cbook.is_string_like +is_sequence_of_strings = cbook.is_sequence_of_strings def _process_plot_format(fmt): @@ -6531,6 +6532,10 @@ ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5) ax.legend() + label can also be a sequence of strings. If multiple data is + provided in *x*, the labels are asigned sequentially to the + histograms. + **Example:** .. plot:: mpl_examples/pylab_examples/histogram_demo.py @@ -6711,11 +6716,18 @@ label = kwargs.pop('label', '') - for patch in patches: + if is_string_like(label): + labels = [label] + ['_nolegend_']*(len(patches)-1) + elif is_sequence_of_strings: + labels = list(label) + ['_nolegend_']*(len(patches)-1) + else: + raise ValueError, 'invalid label: must be string or sequence of strings' + + for (patch, lbl) in zip(patches, labels): for p in patch: p.update(kwargs) - p.set_label(label) - label = '_nolegend_' + p.set_label(lbl) + lbl = '_nolegend_' if binsgiven: self.set_autoscale_on(False) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |