FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/statistics/histogram_features.py at main · quantfns/matplotlib · GitHub
quantfns
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
statistics
/
histogram_features.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (46 loc) · 1.72 KB
Breadcrumbs
matplotlib
/
examples
/
statistics
/
histogram_features.py
Copy path
File metadata and controls
59 lines (46 loc) · 1.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
==============================================
Some features of the histogram (hist) function
==============================================
In addition to the basic histogram, this demo shows a few optional features:
* Setting the number of data bins.
* The *density* parameter, which normalizes bin heights so that the integral of
the histogram is 1. The resulting histogram is an approximation of the
probability density function.
Selecting different bin counts and sizes can significantly affect the shape
of a histogram. The Astropy docs have a great section_ on how to select these
parameters.
.. _section: http://docs.astropy.org/en/stable/visualization/histogram.html
"""
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
np
.
random
.
seed
(
19680801
)
# example data
mu
=
100
# mean of distribution
sigma
=
15
# standard deviation of distribution
x
=
mu
+
sigma
*
np
.
random
.
randn
(
437
)
num_bins
=
50
fig
,
ax
=
plt
.
subplots
()
# the histogram of the data
n
,
bins
,
patches
=
ax
.
hist
(
x
,
num_bins
,
density
=
True
)
# add a 'best fit' line
y
=
((
1
/
(
np
.
sqrt
(
2
*
np
.
pi
)
*
sigma
))
*
np
.
exp
(
-
0.5
*
(
1
/
sigma
*
(
bins
-
mu
))
**
2
))
ax
.
plot
(
bins
,
y
,
'--'
)
ax
.
set_xlabel
(
'Smarts'
)
ax
.
set_ylabel
(
'Probability density'
)
ax
.
set_title
(
r'Histogram of IQ: $\mu=100$, $\sigma=15$'
)
# Tweak spacing to prevent clipping of ylabel
fig
.
tight_layout
()
plt
.
show
()
#############################################################################
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.axes.Axes.hist` / `matplotlib.pyplot.hist`
# - `matplotlib.axes.Axes.set_title`
# - `matplotlib.axes.Axes.set_xlabel`
# - `matplotlib.axes.Axes.set_ylabel`
Back
|
FazBrowse Home
|
New Git URL