Skip to content

Commit 5125224

Browse files
michaelgrundseismanweiji14willschlitzer
authored
Add histogram gallery example (#1272)
Gallery example of a histogram with red bars on a gray background. Elevation counts are binned at 5m intervals, and the data is generated from a normal distribution with random noise added. Co-authored-by: Dongdong Tian <seisman.info@gmail.com> Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> Co-authored-by: Will Schlitzer <schlitzer90@gmail.com>
1 parent c7330da commit 5125224

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Histogram
3+
---------
4+
The :meth:`pygmt.Figure.histogram` method can plot regular histograms.
5+
Using the ``series`` parameter allows to set the interval for the width of
6+
each bar. The type of histogram (frequency count or percentage) can be
7+
selected via the ``histtype`` parameter.
8+
"""
9+
10+
import numpy as np
11+
import pygmt
12+
13+
np.random.seed(100)
14+
15+
# generate random elevation data from a normal distribution
16+
mean = 100 # mean of distribution
17+
stddev = 25 # standard deviation of distribution
18+
data = mean + stddev * np.random.randn(521)
19+
20+
fig = pygmt.Figure()
21+
22+
fig.histogram(
23+
table=data,
24+
# define the frame, add title and set background color to
25+
# lightgray, add annotations for x and y axis
26+
frame=['WSne+t"Histogram"+glightgray', 'x+l"Elevation (m)"', 'y+l"Counts"'],
27+
# generate evenly spaced bins by increments of 5
28+
series=5,
29+
# use red3 as color fill for the bars
30+
fill="red3",
31+
# use a pen size of 1p to draw the outlines
32+
pen="1p",
33+
# choose histogram type 0 = counts [default]
34+
histtype=0,
35+
)
36+
37+
fig.show()

0 commit comments

Comments
 (0)