Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24e0ed1

Browse files
committed
Axes.hist: make 'label' an explicit kwarg, like 'color'
svn path=/trunk/matplotlib/; revision=8221
1 parent e79a0bb commit 24e0ed1

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6989,7 +6989,7 @@ def get_shared_y_axes(self):
69896989
def hist(self, x, bins=10, range=None, normed=False, weights=None,
69906990
cumulative=False, bottom=None, histtype='bar', align='mid',
69916991
orientation='vertical', rwidth=None, log=False,
6992-
color=None,
6992+
color=None, label=None,
69936993
**kwargs):
69946994
"""
69956995
call signature::
@@ -7101,23 +7101,20 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
71017101
dataset. Default (*None*) uses the standard line
71027102
color sequence.
71037103
7104-
kwargs are used to update the properties of the hist
7105-
:class:`~matplotlib.patches.Rectangle` instances:
7104+
*label*:
7105+
String, or sequence of strings to match multiple
7106+
datasets. Bar charts yield multiple patches per
7107+
dataset, but only the first gets the label, so
7108+
that the legend command will work as expected::
71067109
7107-
%(Rectangle)s
7108-
7109-
You can use labels for your histogram, and only the first
7110-
:class:`~matplotlib.patches.Rectangle` gets the label (the
7111-
others get the magic string '_nolegend_'. This will make the
7112-
histograms work in the intuitive way for bar charts::
7110+
ax.hist(10+2*np.random.randn(1000), label='men')
7111+
ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5)
7112+
ax.legend()
71137113
7114-
ax.hist(10+2*np.random.randn(1000), label='men')
7115-
ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5)
7116-
ax.legend()
7114+
kwargs are used to update the properties of the
7115+
:class:`~matplotlib.patches.Patch` instances returned by *hist*:
71177116
7118-
label can also be a sequence of strings. If multiple data is
7119-
provided in *x*, the labels are asigned sequentially to the
7120-
histograms.
7117+
%(Patch)s
71217118
71227119
**Example:**
71237120
@@ -7315,9 +7312,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
73157312
self.dataLim.intervaly = (ymin, ymax)
73167313
self.autoscale_view()
73177314

7318-
label = kwargs.pop('label', '_nolegend_')
7319-
7320-
if is_string_like(label):
7315+
if label is None:
7316+
labels = ['_nolegend_']
7317+
elif is_string_like(label):
73217318
labels = [label]
73227319
elif is_sequence_of_strings(label):
73237320
labels = list(label)

0 commit comments

Comments
 (0)