-
Notifications
You must be signed in to change notification settings - Fork 228
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
Gallery example for histogram/plot showing bit and hachure patterns #2323
Comments
I agree, that this would be a good addition to the gallery! Maybe we can split this into two parts:
Here are two rough examples, which maybe can serve as an orientation or starting point: 1. Gallery example for pattern as fill import pygmt
y = 13
fig = pygmt.Figure()
fig.basemap(
region=[0, 12, 0, 12],
projection="X12c",
frame="lrtb",
)
for pattern in [
# pattern number 3
"p3",
# pattern number 19
"p19",
# pattern number 32
"p32",
# pattern number 23
"p23",
# pattern number 23
# with "red" foreground color (+f) and "yellow" background color (+b)
"p23+fred+byellow",
# pattern number 23
# as before but foreground and backround colors inverted
"P23+fred+byellow",
]:
y -= 2
# Plot square with pattern as fill
fig.plot(
x=2,
y=y,
style="s2c",
pen="1p,black",
fill=pattern,
)
# Add text description
fig.text(
x=4,
y=y,
text=pattern,
font="Courier-Bold",
justify="ML",
)
fig.show()
# fig.savefig(fname="fill_pattern.png") 2) Expand exisiting gallery example for histogram # source: https://www.pygmt.org/dev/gallery/histograms/histogram.html
# last access: 2023-01-14
# modified: subplot with second panel using pattern as fill
import numpy as np
import pygmt
np.random.seed(100)
# Generate random elevation data from a normal distribution
mean = 100 # mean of distribution
stddev = 25 # standard deviation of distribution
data = mean + stddev * np.random.randn(521)
fig = pygmt.Figure()
with fig.subplot(
nrows=1, ncols=2, figsize=("13.5c", "5c"), title="Histogram",
):
with fig.set_panel(panel=0):
fig.histogram(
data=data,
# Define the frame, add title and set background color to
# "lightgray", add labels for x and y axes
frame=["WSne+glightgray", "x+lElevation in m", "y+lCounts"],
# Generate evenly spaced bins by increments of 5
series=5,
# Use "red3" as color fill for the bars
fill="red3",
# Use a pen size of 1 point to draw the outlines
pen="1p",
# Choose histogram type 0, i.e., counts [Default]
histtype=0,
)
with fig.set_panel(panel=1):
fig.histogram(
data=data,
frame=["wSne+glightgray", "x+lElevation in m"],
series=5,
# Use pattern number 8 as fill for the bars
# with "lightblue" as background color (+b) and
# "black" as foreground color (+f)
fill="p8+blightblue+fblack",
pen="1p",
histtype=0,
)
fig.show()
# fig.savefig(fname="histogram_pattern.png") |
This statement is inaccurate. I believe any functions that accept
I agree with part 1, but for part 2, I don't think it's necessary. Instead, we may need to have a tutorial to explain what |
Yes, several PyGMT methods (GMT modules) can use
Click to show code
import numpy as np
import pygmt
fig = pygmt.Figure()
with fig.subplot(
nrows=2, ncols=3, figsize=("22.5c", "15c"), title="Pattern as fill",
):
with fig.set_panel(panel=0):
# after: https://www.pygmt.org/dev/gallery/histograms/histogram.html
# last access: 2022/01/15
np.random.seed(100)
stddev = 25 # standard deviation of distribution
mean = 100 # mean of distribution
data = mean + stddev * np.random.randn(521)
fig.histogram(
data=data,
frame="WSne+glightgray",
series=10,
fill="p8+blightblue+fblack",
pen="1p",
histtype=0,
)
with fig.set_panel(panel=1):
fig.basemap(
region="d",
projection="W?",
frame="afg",
)
fig.coast(
land="p23+blightbrown", # -G dry areas
water="p31+blightblue", # -S wet areas
shorelines="1/0.5p,black",
)
with fig.set_panel(panel=2):
# after: https://www.pygmt.org/dev/gallery/lines/wiggle.html
# last access: 2023/01/15
x = np.arange(-10, 8, 0.1)
y = np.zeros(x.size)
z = np.cos(0.5 * np.pi * x) * 50
fig.basemap(
region=[-8, 12, -1, 1],
projection="X?",
frame=["Snlr", "xa2f1"],
)
fig.wiggle(
x=x,
y=y,
z=z,
scale="20c",
fillpositive="p19+bred3+flightgray",
fillnegative="p19+bred3+flightgray+r100",
pen="1.0p",
track="1.0p,blue",
position="jRM+w100",
)
with fig.set_panel(panel=3):
# after: https://www.pygmt.org/dev/gallery/histograms/rose.html
# last access: 2023/01/15
data = pygmt.datasets.load_sample_data(name="fractures")
fig.rose(
length=data.length,
azimuth=data.azimuth,
region=[0, 1, 0, 360],
diameter="?",
sector="10", # pattern does not work with +r
norm=True,
fill="p32+blightblue",
frame=["x0.2g0.2", "y30g30"],# "+gp18"],
pen="1p",
labels="W,E,S,N",
)
# with fig.set_panel(panel=4):
# fig.basemap(
# region=[-12, 50, 30, 70],
# projection="M?",
# frame="afg",
# )
# # TODO: Currently not clear why shift of dcw ???
# fig.coast(
# land="lightgray",
# water="lightblue",
# shorelines="1/0.5p,black",
# borders="1/0.25p,red",
# dcw="=EU+gP15+p0.25p,darkred",
# )
with fig.set_panel(panel=5):
focal_mechanism = dict(strike=330, dip=30, rake=90, magnitude=5)
fig.basemap(
region=[0, 10, 0, 10],
projection="X?",
frame="rltb",
)
fig.meca(
spec=focal_mechanism,
scale="6c",
longitude=5,
latitude=5,
depth=10.0,
G="p8+r100",
E="p31",
L="1p,black",
)
fig.show()
# fig.savefig(fname="fill_pattern_others.png")
I can work on part 1. |
I think |
Reopening because the histogram example mentioned in #2323 (comment) hasn't been done yet, and we might want to add a full tutorial for bit/hachure patterns too. |
Description of the desired feature
Some functions like
histogram
andplot
have a-Gp
or-GP
option (in PyGMT,-G
is aliased tofill
after #1617) that sets bit and hachure patterns like so:@JingHuiTong suggested during the AGU 2022 Fall Meeting that there could be a gallery example for this, showing how to create e.g. histogram bars with these fill patterns, to be placed under https://www.pygmt.org/v0.8.0/gallery/index.html#histograms
Extends #1156.
References:
Are you willing to help implement and maintain this feature?
Maybe
Related PRs and issues
-> gallery example Bit and Hachure Patterns
-> either expand of gallery example Histogram or separat gallery example
-> gallery example Highlight country polygons
-> in case it is planed to also show how pattern can be used the comments up on Add a gallery example showing how to use patterns via the "fill" parameter (or similar parameters) #2329 (comment) may be helpful
The text was updated successfully, but these errors were encountered: