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

Skip to content

Commit 66cb7bb

Browse files
committed
Unremove the normed kwarg to hist().
1 parent 67d0162 commit 66cb7bb

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
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: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6295,7 +6295,8 @@ def table(self, **kwargs):
62956295
def hist(self, x, bins=None, range=None, density=None, weights=None,
62966296
cumulative=False, bottom=None, histtype='bar', align='mid',
62976297
orientation='vertical', rwidth=None, log=False,
6298-
color=None, label=None, stacked=False, **kwargs):
6298+
color=None, label=None, stacked=False, normed=None,
6299+
**kwargs):
62996300
"""
63006301
Plot a histogram.
63016302
@@ -6363,26 +6364,30 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
63636364
number of observations. If *stacked* is also ``True``, the sum of
63646365
the histograms is normalized to 1.
63656366
6366-
Default is ``False``.
6367+
Default is ``None`` for both *normed* and *density*. If either is
6368+
set, then that value will be used. If neither are set, then the
6369+
args will be treated as ``False``.
6370+
6371+
If both *density* and *normed* are set an error is raised.
63676372
63686373
weights : (n, ) array_like or None, optional
6369-
An array of weights, of the same shape as *x*. Each value in
6370-
*x* only contributes its associated weight towards the bin count
6371-
(instead of 1). If *density* is ``True``, the weights are
6372-
normalized, so that the integral of the density over the range
6373-
remains 1.
6374+
An array of weights, of the same shape as *x*. Each value in *x*
6375+
only contributes its associated weight towards the bin count
6376+
(instead of 1). If *normed* or *density* is ``True``,
6377+
the weights are normalized, so that the integral of the density
6378+
over the range remains 1.
63746379
63756380
Default is ``None``
63766381
63776382
cumulative : bool, optional
6378-
If ``True``, then a histogram is computed where each bin gives
6379-
the counts in that bin plus all bins for smaller values. The last
6380-
bin gives the total number of datapoints. If *density* is also
6381-
``True`` then the histogram is normalized such that the last bin
6382-
equals 1. If *cumulative* evaluates to less than 0 (e.g., -1), the
6383-
direction of accumulation is reversed. In this case, if *density*
6384-
is also ``True``, then the histogram is normalized such that the
6385-
first bin equals 1.
6383+
If ``True``, then a histogram is computed where each bin gives the
6384+
counts in that bin plus all bins for smaller values. The last bin
6385+
gives the total number of datapoints. If *normed* or *density*
6386+
is also ``True`` then the histogram is normalized such that the
6387+
last bin equals 1. If *cumulative* evaluates to less than 0
6388+
(e.g., -1), the direction of accumulation is reversed.
6389+
In this case, if *normed* and/or *density* is also ``True``, then
6390+
the histogram is normalized such that the first bin equals 1.
63866391
63876392
Default is ``False``
63886393
@@ -6462,6 +6467,9 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64626467
64636468
Default is ``False``
64646469
6470+
normed : bool, optional
6471+
Deprecated; use the density keyword argument instead.
6472+
64656473
Returns
64666474
-------
64676475
n : array or list of arrays
@@ -6520,6 +6528,15 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65206528
if histtype == 'barstacked' and not stacked:
65216529
stacked = True
65226530

6531+
if density is not None and normed is not None:
6532+
raise ValueError("kwargs 'density' and 'normed' cannot be used "
6533+
"simultaneously. "
6534+
"Please only use 'density', since 'normed'"
6535+
"is deprecated.")
6536+
if normed is not None:
6537+
cbook.warn_deprecated("2.1", name="'normed'", obj_type="kwarg",
6538+
alternative="'density'", removal="3.1")
6539+
65236540
# basic input validation
65246541
input_empty = np.size(x) == 0
65256542
# Massage 'x' for processing.
@@ -6575,6 +6592,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65756592
xmin = min(xmin, np.nanmin(xi))
65766593
xmax = max(xmax, np.nanmax(xi))
65776594
bin_range = (xmin, xmax)
6595+
density = bool(density) or bool(normed)
65786596
if density and not stacked:
65796597
hist_kwargs = dict(range=bin_range, density=density)
65806598
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
@@ -3117,7 +3117,8 @@ def test_hist_stacked_step():
31173117
ax.hist((d1, d2), histtype="step", stacked=True)
31183118

31193119

3120-
@image_comparison(baseline_images=['hist_stacked_normed'])
3120+
@image_comparison(baseline_images=['hist_stacked_normed',
3121+
'hist_stacked_normed'])
31213122
def test_hist_stacked_density():
31223123
# make some data
31233124
d1 = np.linspace(1, 3, 20)
@@ -3126,6 +3127,11 @@ def test_hist_stacked_density():
31263127
fig, ax = plt.subplots()
31273128
ax.hist((d1, d2), stacked=True, density=True)
31283129

3130+
# Also check that the old keyword works.
3131+
fig, ax = plt.subplots()
3132+
with pytest.warns(UserWarning):
3133+
ax.hist((d1, d2), stacked=True, normed=True)
3134+
31293135

31303136
@pytest.mark.parametrize('normed', [False, True])
31313137
@pytest.mark.parametrize('density', [False, True])

0 commit comments

Comments
 (0)