Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add histogram gallery example #1272

Merged
merged 16 commits into from
May 18, 2021
Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions examples/gallery/histograms/histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Histogram
---------
The :meth:`pygmt.Figure.histogram` method can plot regular histograms.
"""

import numpy as np
import pygmt

np.random.seed(100)

# generate example topography data
mu = 100 # mean of distribution
sigma = 25 # standard deviation of distribution
data = mu + sigma * np.random.randn(521)

fig = pygmt.Figure()

fig.histogram(
table=data,
# generate evenly spaced bins by increments of 5
series=5,
# use red3 as color fill for the bars
fill="red3",
# define the frame, add title and set background color to
# lightgray, add annotations for x and y axis
frame=['WSne+t"Histogram"+glightgray', 'x+l"Topography (m)"', 'y+l"Counts"'],
# use a pen size of 1p to draw the outlines
pen="1p",
# choose histogram type 0 = counts [default]
histtype=0,
)

fig.show()