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 aa52a1d

Browse filesBrowse files
committed
DOC: normalizing histograms
1 parent 042d366 commit aa52a1d
Copy full SHA for aa52a1d

File tree

Expand file treeCollapse file tree

1 file changed

+11
-10
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-10
lines changed

‎galleries/examples/statistics/histogram_normalization.py

Copy file name to clipboardExpand all lines: galleries/examples/statistics/histogram_normalization.py
+11-10Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,11 @@
9898
# and (``np.sum(density * np.diff(bins)) == 1``).
9999
#
100100
# This normalization is how `probability density functions
101-
# <https://en.wikipedia.org/wiki/Probability_density_function>`_ are
102-
# defined in statistics. If :math:`X` is a random variable on :math:`x`, then
103-
# :math:`f_X` is is the probability density function if :math:`P[a<X<b] =
104-
# \int_a^b f_X dx`. Note that if the units of x are Volts (for instance), then
105-
# the units of :math:`f_X` are :math:`V^{-1}` or probability per change in
106-
# voltage.
101+
# <https://en.wikipedia.org/wiki/Probability_density_function>`_ are defined in
102+
# statistics. If :math:`X` is a random variable on :math:`x`, then :math:`f_X`
103+
# is is the probability density function if :math:`P[a<X<b] = \int_a^b f_X dx`.
104+
# If the units of x are Volts, then the units of :math:`f_X` are :math:`V^{-1}`
105+
# or probability per change in voltage.
107106
#
108107
# The usefulness of this normalization is a little more clear when we draw from
109108
# a known distribution and try to compare with theory. So, choose 1000 points
@@ -159,10 +158,11 @@
159158
ax['True'].legend(fontsize='small')
160159

161160
# %%
161+
162162
# Sometimes people want to normalize so that the sum of counts is one. This is
163-
# _not_ done with the *density* kwarg, but instead we can set the *weights* to
164-
# 1/N. Note, however, that the amplitude of the histogram still depends on
165-
# width of the bins
163+
# not done with the *density* kwarg, but rather we can get this effects if we
164+
# set the *weights* to 1/N. Note, however, that the amplitude of the histogram
165+
# still depends on width of the bins:
166166

167167
fig, ax = plt.subplots(layout='constrained', figsize=(3.5, 3))
168168

@@ -176,7 +176,8 @@
176176

177177
# %%
178178
# The true value of normalizing is if you do want to compare two distributions
179-
# that have different sized populations:
179+
# that have different sized populations. Here we compare the distribution of
180+
# ``xdata`` with a population of 1000, and ``xdata2`` with 100 members.
180181

181182
xdata2 = rng.normal(size=100)
182183

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.