Skip to content

Commit a3a636d

Browse files
committed
Add a "density" kwarg to hist2d matplotlib#11070
1 parent 4b1e79f commit a3a636d

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

‎lib/matplotlib/axes/_axes.py‎

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

67756775
@_preprocess_data(replace_names=["x", "y", "weights"], label_namer=None)
6776-
def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6776+
def hist2d(self, x, y, bins=10, range=None, density=None, normed=None, weights=None,
67776777
cmin=None, cmax=None, **kwargs):
67786778
"""
67796779
Make a 2D histogram plot.
@@ -6807,11 +6807,22 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
68076807
xmax], [ymin, ymax]]``. All values outside of this range will be
68086808
considered outliers and not tallied in the histogram.
68096809
6810-
normed : bool, optional, default: False
6811-
Normalize histogram.
6810+
density : boolean, optional
6811+
If False, the default, returns the number of samples in each bin.
6812+
If True, returns the probability *density* function at the bin,
6813+
``bin_count / sample_count / bin_area``.
6814+
6815+
Default is ``None`` for both *normed* and *density*. If either is
6816+
set, then that value will be used. If neither are set, then the
6817+
args will be treated as ``False``.
6818+
If both *density* and *normed* are set an error is raised.
6819+
6820+
normed : bool, optional, default: None
6821+
Deprecated; use the density keyword argument instead.
6822+
68126823
68136824
weights : array_like, shape (n, ), optional, default: None
6814-
An array of values w_i weighing each sample (x_i, y_i).
6825+
An array of values w_i weighing each sample (x_i, y_i).
68156826
68166827
cmin : scalar, optional, default: None
68176828
All bins that has count less than cmin will not be displayed and
@@ -6865,7 +6876,16 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
68656876
in effect to gamma correction) can be accomplished with
68666877
`.colors.PowerNorm`.
68676878
"""
6868-
6879+
if density is not None and normed is not None:
6880+
raise ValueError("kwargs 'density' and 'normed' cannot be used "
6881+
"simultaneously. "
6882+
"Please only use 'density', since 'normed'"
6883+
"is deprecated.")
6884+
if normed is not None:
6885+
cbook.warn_deprecated("2.1", name="'normed'", obj_type="kwarg",
6886+
alternative="'density'", removal="3.1")
6887+
6888+
normed = bool(density) or bool(normed)
68696889
h, xedges, yedges = np.histogram2d(x, y, bins=bins, range=range,
68706890
normed=normed, weights=weights)
68716891

0 commit comments

Comments
 (0)