@@ -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:
@@ -5852,9 +5851,9 @@ def table(self, **kwargs):
5852
5851
#### Data analysis
5853
5852
5854
5853
@_preprocess_data (replace_names = ["x" , 'weights' ], label_namer = "x" )
5855
- def hist (self , x , bins = None , range = None , normed = False , weights = None ,
5856
- cumulative = False , bottom = None , histtype = 'bar' , align = 'mid ' ,
5857
- orientation = 'vertical' , rwidth = None , log = False ,
5854
+ def hist (self , x , bins = None , range = None , density = None , normed = None ,
5855
+ weights = None , cumulative = False , bottom = None , histtype = 'bar' ,
5856
+ align = 'mid' , orientation = 'vertical' , rwidth = None , log = False ,
5858
5857
color = None , label = None , stacked = False ,
5859
5858
** kwargs ):
5860
5859
"""
@@ -5900,7 +5899,7 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
5900
5899
5901
5900
Default is ``None``
5902
5901
5903
- normed : boolean, optional
5902
+ density : boolean, optional
5904
5903
If `True`, the first element of the return tuple will
5905
5904
be the counts normalized to form a probability density, i.e.,
5906
5905
the area (or integral) under the histogram will sum to 1.
@@ -5909,7 +5908,11 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
5909
5908
of observations. If `stacked` is also `True`, the sum of the
5910
5909
histograms is normalized to 1.
5911
5910
5912
- Default is ``False``
5911
+ Default is ``None``, behaves as ``False``.
5912
+
5913
+ normed : boolean, optional
5914
+ Will be deprecated, same role as density. For consistency
5915
+ with NumPy 2.0.0 keyword density has been introduced.
5913
5916
5914
5917
weights : (n, ) array_like or None, optional
5915
5918
An array of weights, of the same shape as `x`. Each value in `x`
@@ -6069,6 +6072,11 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6069
6072
if histtype == 'barstacked' and not stacked :
6070
6073
stacked = True
6071
6074
6075
+ if density is not None and normed is not None :
6076
+ raise ValueError ("kwargs 'density' and 'normed' cannot be used"
6077
+ "simultaneously. Please only use 'density', since "
6078
+ "'normed' will be deprecated. " )
6079
+
6072
6080
# process the unit information
6073
6081
self ._process_unit_info (xdata = x , kwargs = kwargs )
6074
6082
x = self .convert_xunits (x )
@@ -6120,11 +6128,11 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6120
6128
xmin = min (xmin , xi .min ())
6121
6129
xmax = max (xmax , xi .max ())
6122
6130
bin_range = (xmin , xmax )
6123
-
6124
- # hist_kwargs = dict(range=range, normed=bool(normed))
6125
- # We will handle the normed kwarg within mpl until we
6126
- # get to the point of requiring numpy >= 1.5.
6127
- hist_kwargs = dict (range = bin_range )
6131
+ density = bool ( density ) or bool ( normed )
6132
+ if density and not stacked :
6133
+ hist_kwargs = dict ( range = bin_range , density = density )
6134
+ else :
6135
+ hist_kwargs = dict (range = bin_range )
6128
6136
6129
6137
n = []
6130
6138
mlast = None
@@ -6135,17 +6143,15 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6135
6143
m = m .astype (float ) # causes problems later if it's an int
6136
6144
if mlast is None :
6137
6145
mlast = np .zeros (len (bins )- 1 , m .dtype )
6138
- if normed and not stacked :
6139
- db = np .diff (bins )
6140
- m = (m .astype (float ) / db ) / m .sum ()
6146
+
6141
6147
if stacked :
6142
6148
if mlast is None :
6143
6149
mlast = np .zeros (len (bins )- 1 , m .dtype )
6144
6150
m += mlast
6145
6151
mlast [:] = m
6146
6152
n .append (m )
6147
6153
6148
- if stacked and normed :
6154
+ if stacked and density :
6149
6155
db = np .diff (bins )
6150
6156
for m in n :
6151
6157
m [:] = (m .astype (float ) / db ) / n [- 1 ].sum ()
@@ -6154,7 +6160,7 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6154
6160
if cbook .is_numlike (cumulative ) and cumulative < 0 :
6155
6161
slc = slice (None , None , - 1 )
6156
6162
6157
- if normed :
6163
+ if density :
6158
6164
n = [(m * np .diff (bins ))[slc ].cumsum ()[slc ] for m in n ]
6159
6165
else :
6160
6166
n = [m [slc ].cumsum ()[slc ] for m in n ]
@@ -6241,13 +6247,14 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
6241
6247
# Setting a minimum of 0 results in problems for log plots
6242
6248
if np .min (bottom ) > 0 :
6243
6249
minimum = np .min (bottom )
6244
- elif normed or weights is not None :
6245
- # For normed data, set to minimum data value / logbase
6246
- # (gives 1 full tick-label unit for the lowest filled bin)
6250
+ elif density or weights is not None :
6251
+ # For normed (density = True) data full tick-label unit
6252
+ # for the lowest filled bin)
6247
6253
ndata = np .array (n )
6248
6254
minimum = (np .min (ndata [ndata > 0 ])) / logbase
6249
6255
else :
6250
- # For non-normed data, set the min to 1 / log base,
6256
+ # For non-normed (density = False) data,
6257
+ # set the min to 1 / log base,
6251
6258
# again so that there is 1 full tick-label unit
6252
6259
# for the lowest bin
6253
6260
minimum = 1.0 / logbase
0 commit comments