|
From: <ef...@us...> - 2010-04-05 01:07:09
|
Revision: 8221
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8221&view=rev
Author: efiring
Date: 2010-04-05 01:06:57 +0000 (Mon, 05 Apr 2010)
Log Message:
-----------
Axes.hist: make 'label' an explicit kwarg, like 'color'
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/axes.py
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2010-04-03 23:22:48 UTC (rev 8220)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2010-04-05 01:06:57 UTC (rev 8221)
@@ -6989,7 +6989,7 @@
def hist(self, x, bins=10, range=None, normed=False, weights=None,
cumulative=False, bottom=None, histtype='bar', align='mid',
orientation='vertical', rwidth=None, log=False,
- color=None,
+ color=None, label=None,
**kwargs):
"""
call signature::
@@ -7101,24 +7101,21 @@
dataset. Default (*None*) uses the standard line
color sequence.
- kwargs are used to update the properties of the hist
- :class:`~matplotlib.patches.Rectangle` instances:
+ *label*:
+ String, or sequence of strings to match multiple
+ datasets. Bar charts yield multiple patches per
+ dataset, but only the first gets the label, so
+ that the legend command will work as expected::
- %(Rectangle)s
+ ax.hist(10+2*np.random.randn(1000), label='men')
+ ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5)
+ ax.legend()
- You can use labels for your histogram, and only the first
- :class:`~matplotlib.patches.Rectangle` gets the label (the
- others get the magic string '_nolegend_'. This will make the
- histograms work in the intuitive way for bar charts::
+ kwargs are used to update the properties of the
+ :class:`~matplotlib.patches.Patch` instances returned by *hist*:
- ax.hist(10+2*np.random.randn(1000), label='men')
- ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5)
- ax.legend()
+ %(Patch)s
- 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
@@ -7315,9 +7312,9 @@
self.dataLim.intervaly = (ymin, ymax)
self.autoscale_view()
- label = kwargs.pop('label', '_nolegend_')
-
- if is_string_like(label):
+ if label is None:
+ labels = ['_nolegend_']
+ elif is_string_like(label):
labels = [label]
elif is_sequence_of_strings(label):
labels = list(label)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|