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

Skip to content

Commit ce6ed74

Browse files
committed
Add a "density" kwarg to hist2d #11070
1 parent 566bd8b commit ce6ed74

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6778,7 +6778,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
67786778
return tops, bins, cbook.silent_list('Lists of Patches', patches)
67796779

67806780
@_preprocess_data(replace_names=["x", "y", "weights"], label_namer=None)
6781-
def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6781+
def hist2d(self, x, y, bins=10, range=None, density=None, normed=None, weights=None,
67826782
cmin=None, cmax=None, **kwargs):
67836783
"""
67846784
Make a 2D histogram plot.
@@ -6812,11 +6812,22 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
68126812
xmax], [ymin, ymax]]``. All values outside of this range will be
68136813
considered outliers and not tallied in the histogram.
68146814
6815-
normed : bool, optional, default: False
6816-
Normalize histogram.
6815+
density : boolean, optional
6816+
If False, the default, returns the number of samples in each bin.
6817+
If True, returns the probability *density* function at the bin,
6818+
``bin_count / sample_count / bin_area``.
6819+
6820+
Default is ``None`` for both *normed* and *density*. If either is
6821+
set, then that value will be used. If neither are set, then the
6822+
args will be treated as ``False``.
6823+
If both *density* and *normed* are set an error is raised.
6824+
6825+
normed : bool, optional, default: None
6826+
Deprecated; use the density keyword argument instead.
6827+
68176828
68186829
weights : array_like, shape (n, ), optional, default: None
6819-
An array of values w_i weighing each sample (x_i, y_i).
6830+
An array of values w_i weighing each sample (x_i, y_i).
68206831
68216832
cmin : scalar, optional, default: None
68226833
All bins that has count less than cmin will not be displayed and
@@ -6870,7 +6881,16 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
68706881
in effect to gamma correction) can be accomplished with
68716882
`.colors.PowerNorm`.
68726883
"""
6873-
6884+
if density is not None and normed is not None:
6885+
raise ValueError("kwargs 'density' and 'normed' cannot be used "
6886+
"simultaneously. "
6887+
"Please only use 'density', since 'normed'"
6888+
"is deprecated.")
6889+
if normed is not None:
6890+
cbook.warn_deprecated("2.1", name="'normed'", obj_type="kwarg",
6891+
alternative="'density'", removal="3.1")
6892+
6893+
normed = bool(density) or bool(normed)
68746894
h, xedges, yedges = np.histogram2d(x, y, bins=bins, range=range,
68756895
normed=normed, weights=weights)
68766896

0 commit comments

Comments
 (0)