Skip to content

Commit 127adc7

Browse files
dstansbyMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #13459: Document histogramming pre-binned data.
1 parent d966e54 commit 127adc7

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6375,10 +6375,11 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
63756375
"""
63766376
Plot a histogram.
63776377
6378-
Compute and draw the histogram of *x*. The return value is a
6379-
tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*,
6380-
[*patches0*, *patches1*,...]) if the input contains multiple
6381-
data.
6378+
Compute and draw the histogram of *x*. The return value is a tuple
6379+
(*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*, [*patches0*,
6380+
*patches1*,...]) if the input contains multiple data. See the
6381+
documentation of the *weights* parameter to draw a histogram of
6382+
already-binned data.
63826383
63836384
Multiple data can be provided via *x* as a list of datasets
63846385
of potentially different length ([*x0*, *x1*, ...]), or as
@@ -6452,7 +6453,16 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64526453
the weights are normalized, so that the integral of the density
64536454
over the range remains 1.
64546455
6455-
Default is ``None``
6456+
Default is ``None``.
6457+
6458+
This parameter can be used to draw a histogram of data that has
6459+
already been binned, e.g. using `np.histogram` (by treating each
6460+
bin as a single point with a weight equal to its count) ::
6461+
6462+
counts, bins = np.histogram(data)
6463+
plt.hist(bins[:-1], bins, weights=counts)
6464+
6465+
(or you may alternatively use `~.bar()`).
64566466
64576467
cumulative : bool, optional
64586468
If ``True``, then a histogram is computed where each bin gives the

0 commit comments

Comments
 (0)