Revision: 8218
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8218&view=rev
Author: efiring
Date: 2010-04-02 21:29:38 + (Fri, 02 Apr 2010)
Log Message:
---
Axes.hist: style changes, bug fixes
Modified Paths:
--
trunk/matplotlib/lib/matplotlib/axes.py
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===
--- trunk/matplotlib/lib/matplotlib/axes.py 2010-04-02 18:47:00 UTC (rev
8217)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2010-04-02 21:29:38 UTC (rev
8218)
@@ -5311,7 +5311,7 @@
s = np.ma.ravel(s) # This doesn't have to match x, y in size.
-c_is_stringy = is_string_like(c) or cbook.is_sequence_of_strings(c)
+c_is_stringy = is_string_like(c) or is_sequence_of_strings(c)
if not c_is_stringy:
c = np.asanyarray(c)
if c.size == x.size:
@@ -6989,6 +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,
**kwargs):
"""
call signature::
@@ -7002,16 +7003,21 @@
[*patches0*, *patches1*,...]) if the input contains multiple
data.
+Multiple data can be provided via *x* as a list of datasets
+of potentially different length ([*x0*, *x1*, ...]), or as
+a 2-D ndarray in which each column is a dataset. Note that
+the ndarray form is transposed relative to the list form.
+
+Masked arrays are not supported at present.
+
Keyword arguments:
*bins*:
Either an integer number of bins or a sequence giving the
-bins. *x* are the data to be binned. *x* can be an array,
-a 2D array with multiple data in its columns, or a list of
-arrays with data of different length. Note, if *bins*
-is an integer input argument=numbins, *bins* + 1 bin edges
-will be returned, compatible with the semantics of
-:func:`numpy.histogram` with the *new* = True argument.
+bins. If *bins* is an integer, *bins* + 1 bin edges
+will be returned, consistent with :func:`numpy.histogram`
+for numpy version >= 1.3, and with the *new* = True argument
+in earlier versions.
Unequally spaced bins are supported if *bins* is a sequence.
*range*:
@@ -7090,6 +7096,9 @@
be filtered out and only the non-empty (*n*, *bins*,
*patches*) will be returned.
+ *color*:
+
+
kwargs are used to update the properties of the hist
:class:`~matplotlib.patches.Rectangle` instances:
@@ -7117,65 +7126,74 @@
# NOTE: the range keyword overwrites the built-in func range !!!
# needs to be fixed in numpy !!!
+# Validate string inputs here so we don't have to clutter
+# subsequent code.
+if histtype not in ['bar', 'barstacked', 'step', 'stepfilled']:
+raise ValueError("histtype %s is not recognized" % histtype)
+
+if align not in ['left', 'mid', 'right']:
+raise ValueError("align kwarg %s is not recognized" % align)
+
+if orientation not in [ 'horizontal', 'vertical']:
+raise ValueError(
+"orientation kwarg %s is not recognized" % orientation)
+
+
if kwargs.get('width') is not None:
raise DeprecationWarning(
'hist now uses the rwidth to give relative width '
'and not absolute width')
-try:
-# make sure a copy is created: don't use asarray
-x = np.transpose(np.array(x))
-if len(x.shape)==1:
-x.shape = (1,x.shape[0])
-elif len(x.shape)==2 and x.shape[1]1: dr = 0.8
-else: dr = 1.0
+if rwidth is not None:
+dr = min(1.0, max(0.0, rwidth))
+elif len(n)>1:
+dr = 0.8
+else:
+dr = 1.0
if histtype=='bar':
-width = dr*totwidth/len(n)
+width = dr*totwidth/nx
dw = width
-if len(n)>1:
-boffset = -0.5*dr*totwidth*(1.-1./len(n))
+if nx > 1:
+boffset = -0.5*dr*totwidth*(1.0-1.0/nx)
else:
boffset = 0.0
+stacked = False
elif histtype=='barstacked':
width = dr*totwidth
boffset, dw = 0.0, 0.0
-
stacked = True
-else:
-raise ValueError, 'invalid histtype: %s' % histtype
if align == 'mid' or align == 'edge':
boffset += 0.5*totwidth