You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Gallery example for histogram/plot showing bit and hachure patterns #2323
Some functions like histogram and plot have a -Gp or -GP option (in PyGMT, -G is aliased to fill after #1617) that sets bit and hachure patterns like so:
Here are two rough examples, which maybe can serve as an orientation or starting point:
1. Gallery example for pattern as fill
importpygmty=13fig=pygmt.Figure()
fig.basemap(
region=[0, 12, 0, 12],
projection="X12c",
frame="lrtb",
)
forpatternin [
# 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 fillfig.plot(
x=2,
y=y,
style="s2c",
pen="1p,black",
fill=pattern,
)
# Add text descriptionfig.text(
x=4,
y=y,
text=pattern,
font="Courier-Bold",
justify="ML",
)
fig.show()
# fig.savefig(fname="fill_pattern.png")
Output figure:
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 fillimportnumpyasnpimportpygmtnp.random.seed(100)
# Generate random elevation data from a normal distributionmean=100# mean of distributionstddev=25# standard deviation of distributiondata=mean+stddev*np.random.randn(521)
fig=pygmt.Figure()
withfig.subplot(
nrows=1, ncols=2, figsize=("13.5c", "5c"), title="Histogram",
):
withfig.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 axesframe=["WSne+glightgray", "x+lElevation in m", "y+lCounts"],
# Generate evenly spaced bins by increments of 5series=5,
# Use "red3" as color fill for the barsfill="red3",
# Use a pen size of 1 point to draw the outlinespen="1p",
# Choose histogram type 0, i.e., counts [Default]histtype=0,
)
withfig.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")
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 fill GMT/PyGMT can accept, including color names, RGB/HSV/CMYK/gray values, and these patterns.
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 fill GMT/PyGMT can accept, including color names, RGB/HSV/CMYK/gray values, and these patterns.
I can work on part 1.
A tutorial is probably a more general way to explain the "functionality" of fill, which indirectly addresses all related methods. Maybe pygmt.Figure.histogram was only exemplary suggested, because bars of histograms are often filled with pattern.
I think pygmt.Figure.histogram could be one of examples to show how to use fill.
Because when I used 2 colors (red, blue)with transparency, it looks like 3 colors (red, blue, purple) in a figure.
That's why I suggested the histogram bars with these fill patterns will be more clearly.
Maybe it can insert into part1.
Surly, the function still based on users how to apply.
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.
What's the status of this issue? Can it be closed after #4020 is merged?
I think there was the idea to have another gallery example to show the effect of plotting two histograms on top of each other when using semi-transparent colors or patterns (see comment #2323 (comment)). But I think such an example is not essentially required.
Activity
yvonnefroehlich commentedon Jan 14, 2023
I agree, that this would be a good addition to the gallery! Maybe we can split this into two parts:
fill(e.g., https://www.pygmt.org/dev/api/generated/pygmt.Figure.plot.html#pygmt.Figure.plot)Here are two rough examples, which maybe can serve as an orientation or starting point:
1. Gallery example for pattern as fill
Output figure:

2) Expand exisiting gallery example for histogram
Output figure:

seisman commentedon Jan 15, 2023
This statement is inaccurate. I believe any functions that accept
fillas an argument (e.g.,coast's-Gand-S) can use bit and hachure patterns.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
fillGMT/PyGMT can accept, including color names, RGB/HSV/CMYK/gray values, and these patterns.yvonnefroehlich commentedon Jan 15, 2023
Yes, several PyGMT methods (GMT modules) can use
fillor related parameters with a pattern, e.g.:pygmt.Figure.plot:fillpygmt.Figure.histogram:fillpygmt.Figure.coast:land,waterpygmt.Figure.wiggle:fillpositive,fillnegativepygmt.Figure.rose:fill(does NOT work for+rinsector)pygmt.Figure.meca:G,EClick to show code
I can work on part 1.
A tutorial is probably a more general way to explain the "functionality" of
fill, which indirectly addresses all related methods. Maybepygmt.Figure.histogramwas only exemplary suggested, because bars of histograms are often filled with pattern.jhtong33 commentedon Jan 16, 2023
I think
pygmt.Figure.histogramcould be one of examples to show how to usefill.Because when I used 2 colors (red, blue)with transparency, it looks like 3 colors (red, blue, purple) in a figure.
That's why I suggested the histogram bars with these fill patterns will be more clearly.
Maybe it can insert into part1.
Surly, the function still based on users how to apply.
some examples I plotted before.


weiji14 commentedon Mar 14, 2023
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.
seisman commentedon Sep 24, 2025
What's the status of this issue? Can it be closed after #4020 is merged?
yvonnefroehlich commentedon Sep 28, 2025
I think there was the idea to have another gallery example to show the effect of plotting two histograms on top of each other when using semi-transparent colors or patterns (see comment #2323 (comment)). But I think such an example is not essentially required.