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

Skip to content

Commit 3574feb

Browse files
authored
Merge pull request #16149 from jklymak/doc-reword-hist-density
DOC: reword density desc in `ax.hist`
2 parents 262c67f + 82c37e1 commit 3574feb

File tree

1 file changed

+19
-32
lines changed

1 file changed

+19
-32
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6351,7 +6351,7 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
63516351
supported by `numpy.histogram_bin_edges`: 'auto', 'fd', 'doane',
63526352
'scott', 'stone', 'rice', 'sturges', or 'sqrt'.
63536353
6354-
range : tuple or None, optional
6354+
range : tuple or None, optional, default: None
63556355
The lower and upper range of the bins. Lower and upper outliers
63566356
are ignored. If not provided, *range* is ``(x.min(), x.max())``.
63576357
Range has no effect if *bins* is a sequence.
@@ -6360,28 +6360,25 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
63606360
is based on the specified bin range instead of the
63616361
range of x.
63626362
6363-
Default is ``None``
6364-
6365-
density : bool, optional
6363+
density : bool, optional, default: False
63666364
If ``True``, the first element of the return tuple will
6367-
be the counts normalized to form a probability density, i.e.,
6368-
the area (or integral) under the histogram will sum to 1.
6369-
This is achieved by dividing the count by the number of
6370-
observations times the bin width and not dividing by the total
6371-
number of observations. If *stacked* is also ``True``, the sum of
6372-
the histograms is normalized to 1.
6365+
be the raw counts per bin normalized to form a probability density
6366+
so that the area under the histogram will integrate to 1, i.e.
6367+
``np.sum(n * np.diff(bins)) == 1``. (Computed by dividing the
6368+
raw counts ``n0`` by the total number of data points and
6369+
multiplying by the bin width: ``n = n0 / sum(n0) * np.diff(bins)``)
6370+
6371+
If *stacked* is also ``True``, the sum of the histograms is
6372+
normalized to 1.
63736373
6374-
Default is ``False``.
63756374
6376-
weights : (n, ) array-like or None, optional
6375+
weights : (n, ) array-like or None, optional, default: None
63776376
An array of weights, of the same shape as *x*. Each value in *x*
63786377
only contributes its associated weight towards the bin count
63796378
(instead of 1). If *normed* or *density* is ``True``,
63806379
the weights are normalized, so that the integral of the density
63816380
over the range remains 1.
63826381
6383-
Default is ``None``.
6384-
63856382
This parameter can be used to draw a histogram of data that has
63866383
already been binned, e.g. using `numpy.histogram` (by treating each
63876384
bin as a single point with a weight equal to its count) ::
@@ -6391,7 +6388,7 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
63916388
63926389
(or you may alternatively use `~.bar()`).
63936390
6394-
cumulative : bool or -1, optional
6391+
cumulative : bool or -1, optional, default: False
63956392
If ``True``, then a histogram is computed where each bin gives the
63966393
counts in that bin plus all bins for smaller values. The last bin
63976394
gives the total number of datapoints.
@@ -6404,15 +6401,13 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
64046401
``True``, then the histogram is normalized such that the first bin
64056402
equals 1.
64066403
6407-
Default is ``False``
64086404
6409-
bottom : array-like, scalar, or None
6405+
bottom : array-like, scalar, or None, default: None
64106406
Location of the bottom baseline of each bin. If a scalar,
64116407
the base line for each bin is shifted by the same amount.
64126408
If an array, each bin is shifted independently and the length
64136409
of bottom must match the number of bins. If None, defaults to 0.
64146410
6415-
Default is ``None``
64166411
64176412
histtype : {'bar', 'barstacked', 'step', 'stepfilled'}, optional
64186413
The type of histogram to draw.
@@ -6426,55 +6421,47 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
64266421
64276422
Default is 'bar'
64286423
6429-
align : {'left', 'mid', 'right'}, optional
6424+
align : {'left', 'mid', 'right'}, optional, default 'mid'
64306425
The horizontal alignment of the histogram bars.
64316426
64326427
- 'left': bars are centered on the left bin edges.
64336428
- 'mid': bars are centered between the bin edges.
64346429
- 'right': bars are centered on the right bin edges.
64356430
6436-
Default is 'mid'
64376431
64386432
orientation : {'horizontal', 'vertical'}, optional
64396433
If 'horizontal', `~matplotlib.pyplot.barh` will be used for
64406434
bar-type histograms and the *bottom* kwarg will be the left edges.
64416435
6442-
rwidth : scalar or None, optional
6436+
rwidth : scalar or None, optional, default: None
64436437
The relative width of the bars as a fraction of the bin width. If
64446438
``None``, automatically compute the width.
64456439
64466440
Ignored if *histtype* is 'step' or 'stepfilled'.
64476441
6448-
Default is ``None``
64496442
6450-
log : bool, optional
6443+
log : bool, optional, default: False
64516444
If ``True``, the histogram axis will be set to a log scale. If
64526445
*log* is ``True`` and *x* is a 1D array, empty bins will be
64536446
filtered out and only the non-empty ``(n, bins, patches)``
64546447
will be returned.
64556448
6456-
Default is ``False``
6457-
6458-
color : color or array-like of colors or None, optional
6449+
color : color or array-like of colors or None, optional, default: None
64596450
Color or sequence of colors, one per dataset. Default (``None``)
64606451
uses the standard line color sequence.
64616452
64626453
Default is ``None``
64636454
6464-
label : str or None, optional
6455+
label : str or None, optional, default: None
64656456
String, or sequence of strings to match multiple datasets. Bar
64666457
charts yield multiple patches per dataset, but only the first gets
64676458
the label, so that the legend command will work as expected.
64686459
6469-
default is ``None``
6470-
6471-
stacked : bool, optional
6460+
stacked : bool, optional, default:False
64726461
If ``True``, multiple data are stacked on top of each other If
64736462
``False`` multiple data are arranged side by side if histtype is
64746463
'bar' or on top of each other if histtype is 'step'
64756464
6476-
Default is ``False``
6477-
64786465
Returns
64796466
-------
64806467
n : array or list of arrays

0 commit comments

Comments
 (0)