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

Skip to content

Commit 7c72ea1

Browse files
committed
Unremove the normed kwarg to hist().
1 parent 00480ad commit 7c72ea1

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

doc/api/next_api_changes/2018-09-18-AL-removals.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Classes and methods
2020

2121
Arguments
2222
---------
23-
- The ``normed`` kwarg to ``Axes.hist``
2423
- The ``fig`` kwarg to ``GridSpec.get_subplot_params`` and
2524
``GridSpecFromSubplotSpec.get_subplot_params``
2625
- Passing 'box-forced' to `axes.Axes.set_adjustable`

lib/matplotlib/axes/_axes.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6324,7 +6324,8 @@ def table(self, **kwargs):
63246324
def hist(self, x, bins=None, range=None, density=None, weights=None,
63256325
cumulative=False, bottom=None, histtype='bar', align='mid',
63266326
orientation='vertical', rwidth=None, log=False,
6327-
color=None, label=None, stacked=False, **kwargs):
6327+
color=None, label=None, stacked=False, normed=None,
6328+
**kwargs):
63286329
"""
63296330
Plot a histogram.
63306331
@@ -6392,26 +6393,30 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
63926393
number of observations. If *stacked* is also ``True``, the sum of
63936394
the histograms is normalized to 1.
63946395
6395-
Default is ``False``.
6396+
Default is ``None`` for both *normed* and *density*. If either is
6397+
set, then that value will be used. If neither are set, then the
6398+
args will be treated as ``False``.
6399+
6400+
If both *density* and *normed* are set an error is raised.
63966401
63976402
weights : (n, ) array_like or None, optional
6398-
An array of weights, of the same shape as *x*. Each value in
6399-
*x* only contributes its associated weight towards the bin count
6400-
(instead of 1). If *density* is ``True``, the weights are
6401-
normalized, so that the integral of the density over the range
6402-
remains 1.
6403+
An array of weights, of the same shape as *x*. Each value in *x*
6404+
only contributes its associated weight towards the bin count
6405+
(instead of 1). If *normed* or *density* is ``True``,
6406+
the weights are normalized, so that the integral of the density
6407+
over the range remains 1.
64036408
64046409
Default is ``None``
64056410
64066411
cumulative : bool, optional
6407-
If ``True``, then a histogram is computed where each bin gives
6408-
the counts in that bin plus all bins for smaller values. The last
6409-
bin gives the total number of datapoints. If *density* is also
6410-
``True`` then the histogram is normalized such that the last bin
6411-
equals 1. If *cumulative* evaluates to less than 0 (e.g., -1), the
6412-
direction of accumulation is reversed. In this case, if *density*
6413-
is also ``True``, then the histogram is normalized such that the
6414-
first bin equals 1.
6412+
If ``True``, then a histogram is computed where each bin gives the
6413+
counts in that bin plus all bins for smaller values. The last bin
6414+
gives the total number of datapoints. If *normed* or *density*
6415+
is also ``True`` then the histogram is normalized such that the
6416+
last bin equals 1. If *cumulative* evaluates to less than 0
6417+
(e.g., -1), the direction of accumulation is reversed.
6418+
In this case, if *normed* and/or *density* is also ``True``, then
6419+
the histogram is normalized such that the first bin equals 1.
64156420
64166421
Default is ``False``
64176422
@@ -6491,15 +6496,19 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64916496
64926497
Default is ``False``
64936498
6499+
normed : bool, optional
6500+
Deprecated; use the density keyword argument instead.
6501+
64946502
Returns
64956503
-------
64966504
n : array or list of arrays
6497-
The values of the histogram bins. See *density* and *weights* for a
6498-
description of the possible semantics. If input *x* is an array,
6499-
then this is an array of length *nbins*. If input is a sequence of
6500-
arrays ``[data1, data2,..]``, then this is a list of arrays with
6501-
the values of the histograms for each of the arrays in the same
6502-
order.
6505+
The values of the histogram bins. See *normed* or *density*
6506+
and *weights* for a description of the possible semantics.
6507+
If input *x* is an array, then this is an array of length
6508+
*nbins*. If input is a sequence of arrays
6509+
``[data1, data2,..]``, then this is a list of arrays with
6510+
the values of the histograms for each of the arrays in the
6511+
same order.
65036512
65046513
bins : array
65056514
The edges of the bins. Length nbins + 1 (nbins left edges and right
@@ -6548,6 +6557,15 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65486557
if histtype == 'barstacked' and not stacked:
65496558
stacked = True
65506559

6560+
if density is not None and normed is not None:
6561+
raise ValueError("kwargs 'density' and 'normed' cannot be used "
6562+
"simultaneously. "
6563+
"Please only use 'density', since 'normed'"
6564+
"is deprecated.")
6565+
if normed is not None:
6566+
cbook.warn_deprecated("2.1", name="'normed'", obj_type="kwarg",
6567+
alternative="'density'", removal="3.1")
6568+
65516569
# basic input validation
65526570
input_empty = np.size(x) == 0
65536571
# Massage 'x' for processing.
@@ -6603,6 +6621,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
66036621
xmin = min(xmin, np.nanmin(xi))
66046622
xmax = max(xmax, np.nanmax(xi))
66056623
bin_range = (xmin, xmax)
6624+
density = bool(density) or bool(normed)
66066625
if density and not stacked:
66076626
hist_kwargs = dict(range=bin_range, density=density)
66086627
else:

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,13 +2618,14 @@ def hist(
26182618
x, bins=None, range=None, density=None, weights=None,
26192619
cumulative=False, bottom=None, histtype='bar', align='mid',
26202620
orientation='vertical', rwidth=None, log=False, color=None,
2621-
label=None, stacked=False, *, data=None, **kwargs):
2621+
label=None, stacked=False, normed=None, *, data=None,
2622+
**kwargs):
26222623
return gca().hist(
26232624
x, bins=bins, range=range, density=density, weights=weights,
26242625
cumulative=cumulative, bottom=bottom, histtype=histtype,
26252626
align=align, orientation=orientation, rwidth=rwidth, log=log,
2626-
color=color, label=label, stacked=stacked, **({"data": data} if data is
2627-
not None else {}), **kwargs)
2627+
color=color, label=label, stacked=stacked, normed=normed,
2628+
**({"data": data} if data is not None else {}), **kwargs)
26282629

26292630

26302631
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,8 @@ def test_hist_stacked_step():
30703070
ax.hist((d1, d2), histtype="step", stacked=True)
30713071

30723072

3073-
@image_comparison(baseline_images=['hist_stacked_normed'])
3073+
@image_comparison(baseline_images=['hist_stacked_normed',
3074+
'hist_stacked_normed'])
30743075
def test_hist_stacked_density():
30753076
# make some data
30763077
d1 = np.linspace(1, 3, 20)
@@ -3079,6 +3080,11 @@ def test_hist_stacked_density():
30793080
fig, ax = plt.subplots()
30803081
ax.hist((d1, d2), stacked=True, density=True)
30813082

3083+
# Also check that the old keyword works.
3084+
fig, ax = plt.subplots()
3085+
with pytest.warns(UserWarning):
3086+
ax.hist((d1, d2), stacked=True, normed=True)
3087+
30823088

30833089
@pytest.mark.parametrize('normed', [False, True])
30843090
@pytest.mark.parametrize('density', [False, True])

0 commit comments

Comments
 (0)