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 127adc7

Browse filesBrowse files
dstansbyMeeseeksDev[bot]
authored andcommitted
Backport PR #13459: Document histogramming pre-binned data.
1 parent d966e54 commit 127adc7
Copy full SHA for 127adc7

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
@@ -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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.