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

Skip to content

Commit eae2b7f

Browse files
committed
Document histogramming pre-binned data.
This simple solution is slightly modified from an original idea by @mhedges.
1 parent b9045cd commit eae2b7f

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6410,10 +6410,11 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64106410
"""
64116411
Plot a histogram.
64126412
6413-
Compute and draw the histogram of *x*. The return value is a
6414-
tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*,
6415-
[*patches0*, *patches1*,...]) if the input contains multiple
6416-
data.
6413+
Compute and draw the histogram of *x*. The return value is a tuple
6414+
(*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*, [*patches0*,
6415+
*patches1*,...]) if the input contains multiple data. See the
6416+
documentation of the *weights* parameter to draw a histogram of
6417+
already-binned data.
64176418
64186419
Multiple data can be provided via *x* as a list of datasets
64196420
of potentially different length ([*x0*, *x1*, ...]), or as
@@ -6487,7 +6488,16 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64876488
the weights are normalized, so that the integral of the density
64886489
over the range remains 1.
64896490
6490-
Default is ``None``
6491+
Default is ``None``.
6492+
6493+
This parameter can be used to draw a histogram of data that has
6494+
already been binned, e.g. using `np.histogram` (by treating each
6495+
bin as a single point with a weight equal to its count) ::
6496+
6497+
counts, bins = np.histogram(data)
6498+
plt.hist(bins[:-1], bins, weights=counts)
6499+
6500+
(or you may alternatively use `~.bar()`).
64916501
64926502
cumulative : bool, optional
64936503
If ``True``, then a histogram is computed where each bin gives the

0 commit comments

Comments
 (0)