@@ -91,7 +91,6 @@ def _plot_args_replacer(args, data):
91
91
# The axes module contains all the wrappers to plotting functions.
92
92
# All the other methods should go in the _AxesBase class.
93
93
94
-
95
94
class Axes (_AxesBase ):
96
95
"""
97
96
The :class:`Axes` contains most of the figure elements:
@@ -5870,10 +5869,10 @@ def table(self, **kwargs):
5870
5869
#### Data analysis
5871
5870
5872
5871
@_preprocess_data (replace_names = ["x" , 'weights' ], label_namer = "x" )
5873
- def hist (self , x , bins = None , range = None , normed = False , weights = None ,
5872
+ def hist (self , x , bins = None , range = None , density = None , weights = None ,
5874
5873
cumulative = False , bottom = None , histtype = 'bar' , align = 'mid' ,
5875
5874
orientation = 'vertical' , rwidth = None , log = False ,
5876
- color = None , label = None , stacked = False ,
5875
+ color = None , label = None , stacked = False , normed = None ,
5877
5876
** kwargs ):
5878
5877
"""
5879
5878
Plot a histogram.
@@ -5897,55 +5896,60 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
5897
5896
arrays which are not required to be of the same length
5898
5897
5899
5898
bins : integer or array_like or 'auto', optional
5900
- If an integer is given, `bins + 1` bin edges are returned,
5899
+ If an integer is given, `` bins + 1` ` bin edges are returned,
5901
5900
consistently with :func:`numpy.histogram` for numpy version >=
5902
5901
1.3.
5903
5902
5904
- Unequally spaced bins are supported if ` bins` is a sequence.
5903
+ Unequally spaced bins are supported if * bins* is a sequence.
5905
5904
5906
5905
If Numpy 1.11 is installed, may also be ``'auto'``.
5907
5906
5908
5907
Default is taken from the rcParam ``hist.bins``.
5909
5908
5910
5909
range : tuple or None, optional
5911
5910
The lower and upper range of the bins. Lower and upper outliers
5912
- are ignored. If not provided, ` range` is (x.min(), x.max()). Range
5913
- has no effect if ` bins` is a sequence.
5911
+ are ignored. If not provided, * range* is `` (x.min(), x.max())``.
5912
+ Range has no effect if * bins* is a sequence.
5914
5913
5915
- If ` bins` is a sequence or ` range` is specified, autoscaling
5914
+ If * bins* is a sequence or * range* is specified, autoscaling
5916
5915
is based on the specified bin range instead of the
5917
5916
range of x.
5918
5917
5919
5918
Default is ``None``
5920
5919
5921
- normed : boolean, optional
5922
- If `True`, the first element of the return tuple will
5920
+ density : boolean, optional
5921
+ If `` True` `, the first element of the return tuple will
5923
5922
be the counts normalized to form a probability density, i.e.,
5924
5923
the area (or integral) under the histogram will sum to 1.
5925
- This is achieved dividing the count by the number of observations
5926
- times the bin width and * not* dividing by the total number
5927
- of observations. If ` stacked` is also `True`, the sum of the
5928
- histograms is normalized to 1.
5924
+ This is achieved by dividing the count by the number of
5925
+ observations times the bin width and not dividing by the total
5926
+ number of observations. If * stacked* is also `` True`` , the sum of
5927
+ the histograms is normalized to 1.
5929
5928
5930
- Default is ``False``
5929
+ Default is ``None`` for both *normed* and *density*. If either is
5930
+ set, then that value will be used. If neither are set, then the
5931
+ args will be treated as ``False``.
5932
+
5933
+ If both *density* and *normed* are set an error is raised.
5931
5934
5932
5935
weights : (n, ) array_like or None, optional
5933
- An array of weights, of the same shape as `x` . Each value in `x`
5936
+ An array of weights, of the same shape as *x* . Each value in *x*
5934
5937
only contributes its associated weight towards the bin count
5935
- (instead of 1). If `normed` is True, the weights are normalized,
5936
- so that the integral of the density over the range remains 1.
5938
+ (instead of 1). If *normed* or *density* is ``True``,
5939
+ the weights are normalized, so that the integral of the density
5940
+ over the range remains 1.
5937
5941
5938
5942
Default is ``None``
5939
5943
5940
5944
cumulative : boolean, optional
5941
- If `True`, then a histogram is computed where each bin gives the
5945
+ If `` True` `, then a histogram is computed where each bin gives the
5942
5946
counts in that bin plus all bins for smaller values. The last bin
5943
- gives the total number of datapoints. If ` normed` is also `True`
5944
- then the histogram is normalized such that the last bin equals 1.
5945
- If ` cumulative` evaluates to less than 0 (e.g., -1), the direction
5946
- of accumulation is reversed. In this case, if `normed` is also
5947
- `True`, then the histogram is normalized such that the first bin
5948
- equals 1.
5947
+ gives the total number of datapoints. If * normed* or *density*
5948
+ is also ``True`` then the histogram is normalized such that the
5949
+ last bin equals 1. If * cumulative* evaluates to less than 0
5950
+ (e.g., -1), the direction of accumulation is reversed.
5951
+ In this case, if *normed* and/or *density* is also ``True``, then
5952
+ the histogram is normalized such that the first bin equals 1.
5949
5953
5950
5954
Default is ``False``
5951
5955
@@ -5991,22 +5995,23 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
5991
5995
5992
5996
rwidth : scalar or None, optional
5993
5997
The relative width of the bars as a fraction of the bin width. If
5994
- `None`, automatically compute the width.
5998
+ `` None` `, automatically compute the width.
5995
5999
5996
- Ignored if ` histtype` is 'step' or 'stepfilled'.
6000
+ Ignored if * histtype* is 'step' or 'stepfilled'.
5997
6001
5998
6002
Default is ``None``
5999
6003
6000
6004
log : boolean, optional
6001
- If `True`, the histogram axis will be set to a log scale. If `log`
6002
- is `True` and `x` is a 1D array, empty bins will be filtered out
6003
- and only the non-empty (`n`, `bins`, `patches`) will be returned.
6005
+ If ``True``, the histogram axis will be set to a log scale. If
6006
+ *log* is ``True`` and *x* is a 1D array, empty bins will be
6007
+ filtered out and only the non-empty ``(n, bins, patches)``
6008
+ will be returned.
6004
6009
6005
6010
Default is ``False``
6006
6011
6007
6012
color : color or array_like of colors or None, optional
6008
6013
Color spec or sequence of color specs, one per dataset. Default
6009
- (`None`) uses the standard line color sequence.
6014
+ (`` None` `) uses the standard line color sequence.
6010
6015
6011
6016
Default is ``None``
6012
6017
@@ -6018,21 +6023,22 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6018
6023
default is ``None``
6019
6024
6020
6025
stacked : boolean, optional
6021
- If `True`, multiple data are stacked on top of each other If
6022
- `False` multiple data are aranged side by side if histtype is
6026
+ If `` True` `, multiple data are stacked on top of each other If
6027
+ `` False` ` multiple data are aranged side by side if histtype is
6023
6028
'bar' or on top of each other if histtype is 'step'
6024
6029
6025
6030
Default is ``False``
6026
6031
6027
6032
Returns
6028
6033
-------
6029
6034
n : array or list of arrays
6030
- The values of the histogram bins. See **normed** and **weights**
6031
- for a description of the possible semantics. If input **x** is an
6032
- array, then this is an array of length **nbins**. If input is a
6033
- sequence arrays ``[data1, data2,..]``, then this is a list of
6034
- arrays with the values of the histograms for each of the arrays
6035
- in the same order.
6035
+ The values of the histogram bins. See *normed* or *density*
6036
+ and *weights* for a description of the possible semantics.
6037
+ If input *x* is an array, then this is an array of length
6038
+ *nbins*. If input is a sequence arrays
6039
+ ``[data1, data2,..]``, then this is a list of arrays with
6040
+ the values of the histograms for each of the arrays in the
6041
+ same order.
6036
6042
6037
6043
bins : array
6038
6044
The edges of the bins. Length nbins + 1 (nbins left edges and right
@@ -6054,8 +6060,8 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6054
6060
Notes
6055
6061
-----
6056
6062
Until numpy release 1.5, the underlying numpy histogram function was
6057
- incorrect with `normed`=` True` if bin sizes were unequal. MPL
6058
- inherited that error. It is now corrected within MPL when using
6063
+ incorrect with ``normed= True` ` if bin sizes were unequal. MPL
6064
+ inherited that error. It is now corrected within MPL when using
6059
6065
earlier numpy versions.
6060
6066
6061
6067
"""
@@ -6087,6 +6093,12 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6087
6093
if histtype == 'barstacked' and not stacked :
6088
6094
stacked = True
6089
6095
6096
+ if density is not None and normed is not None :
6097
+ raise ValueError ("kwargs 'density' and 'normed' cannot be used "
6098
+ "simultaneously. "
6099
+ "Please only use 'density', since 'normed'"
6100
+ "will be deprecated." )
6101
+
6090
6102
# process the unit information
6091
6103
self ._process_unit_info (xdata = x , kwargs = kwargs )
6092
6104
x = self .convert_xunits (x )
@@ -6138,11 +6150,11 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6138
6150
xmin = min (xmin , xi .min ())
6139
6151
xmax = max (xmax , xi .max ())
6140
6152
bin_range = (xmin , xmax )
6141
-
6142
- # hist_kwargs = dict(range=range, normed=bool(normed))
6143
- # We will handle the normed kwarg within mpl until we
6144
- # get to the point of requiring numpy >= 1.5.
6145
- hist_kwargs = dict (range = bin_range )
6153
+ density = bool ( density ) or bool ( normed )
6154
+ if density and not stacked :
6155
+ hist_kwargs = dict ( range = bin_range , density = density )
6156
+ else :
6157
+ hist_kwargs = dict (range = bin_range )
6146
6158
6147
6159
n = []
6148
6160
mlast = None
@@ -6153,7 +6165,7 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6153
6165
m = m .astype (float ) # causes problems later if it's an int
6154
6166
if mlast is None :
6155
6167
mlast = np .zeros (len (bins )- 1 , m .dtype )
6156
- if normed and not stacked :
6168
+ if density and not stacked :
6157
6169
db = np .diff (bins )
6158
6170
m = (m .astype (float ) / db ) / m .sum ()
6159
6171
if stacked :
@@ -6163,7 +6175,7 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6163
6175
mlast [:] = m
6164
6176
n .append (m )
6165
6177
6166
- if stacked and normed :
6178
+ if stacked and density :
6167
6179
db = np .diff (bins )
6168
6180
for m in n :
6169
6181
m [:] = (m .astype (float ) / db ) / n [- 1 ].sum ()
@@ -6172,7 +6184,7 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6172
6184
if cbook .is_numlike (cumulative ) and cumulative < 0 :
6173
6185
slc = slice (None , None , - 1 )
6174
6186
6175
- if normed :
6187
+ if density :
6176
6188
n = [(m * np .diff (bins ))[slc ].cumsum ()[slc ] for m in n ]
6177
6189
else :
6178
6190
n = [m [slc ].cumsum ()[slc ] for m in n ]
@@ -6259,13 +6271,15 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6259
6271
# Setting a minimum of 0 results in problems for log plots
6260
6272
if np .min (bottom ) > 0 :
6261
6273
minimum = np .min (bottom )
6262
- elif normed or weights is not None :
6263
- # For normed data, set to minimum data value / logbase
6274
+ elif density or weights is not None :
6275
+ # For data that is normed to form a probability density,
6276
+ # set to minimum data value / logbase
6264
6277
# (gives 1 full tick-label unit for the lowest filled bin)
6265
6278
ndata = np .array (n )
6266
6279
minimum = (np .min (ndata [ndata > 0 ])) / logbase
6267
6280
else :
6268
- # For non-normed data, set the min to 1 / log base,
6281
+ # For non-normed (density = False) data,
6282
+ # set the min to 1 / log base,
6269
6283
# again so that there is 1 full tick-label unit
6270
6284
# for the lowest bin
6271
6285
minimum = 1.0 / logbase
0 commit comments