Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eae2b7f

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

File tree

Expand file treeCollapse file tree

1 file changed

+15
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-5
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+15-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.