Skip to content

Commit 9ec3ee6

Browse files
committed
labels for multiple data histograms
svn path=/trunk/matplotlib/; revision=6583
1 parent 5c43f81 commit 9ec3ee6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-12-12 Added support to asign labels to histograms of multiple
2+
data. - MM
3+
14
=================================================================
25
2008-12-11 Released 0.98.5 at svn r6573
36

lib/matplotlib/axes.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
iterable = cbook.iterable
3131
is_string_like = cbook.is_string_like
32+
is_sequence_of_strings = cbook.is_sequence_of_strings
3233

3334

3435
def _process_plot_format(fmt):
@@ -6531,6 +6532,10 @@ def hist(self, x, bins=10, range=None, normed=False, cumulative=False,
65316532
ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5)
65326533
ax.legend()
65336534
6535+
label can also be a sequence of strings. If multiple data is
6536+
provided in *x*, the labels are asigned sequentially to the
6537+
histograms.
6538+
65346539
**Example:**
65356540
65366541
.. plot:: mpl_examples/pylab_examples/histogram_demo.py
@@ -6711,11 +6716,18 @@ def hist(self, x, bins=10, range=None, normed=False, cumulative=False,
67116716

67126717
label = kwargs.pop('label', '')
67136718

6714-
for patch in patches:
6719+
if is_string_like(label):
6720+
labels = [label] + ['_nolegend_']*(len(patches)-1)
6721+
elif is_sequence_of_strings:
6722+
labels = list(label) + ['_nolegend_']*(len(patches)-1)
6723+
else:
6724+
raise ValueError, 'invalid label: must be string or sequence of strings'
6725+
6726+
for (patch, lbl) in zip(patches, labels):
67156727
for p in patch:
67166728
p.update(kwargs)
6717-
p.set_label(label)
6718-
label = '_nolegend_'
6729+
p.set_label(lbl)
6730+
lbl = '_nolegend_'
67196731

67206732
if binsgiven:
67216733
self.set_autoscale_on(False)

0 commit comments

Comments
 (0)