Skip to content

Commit 91e29f1

Browse files
yvonnefroehlichseismanmichaelgrund
authored
Add gallery example "Decorated lines" (style="~") (#2564)
Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Michael Grund <[email protected]>
1 parent 301b222 commit 91e29f1

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""
2+
Decorated lines
3+
---------------
4+
To draw a so-called *decorated line*, i.e., symbols along a line
5+
or curve, use the ``style`` parameter of the
6+
:meth:`pygmt.Figure.plot` method with the argument ``"~"`` and the
7+
desired modifiers. A colon (``":"``) is used to separate the
8+
algorithm settings from the symbol information.
9+
This example shows how to adjust the symbols.
10+
Beside the built-in symbols also custom symbols can be used.
11+
For modifying the baseline via the ``pen`` parameter, see the
12+
:doc:`Line styles example </gallery/lines/linestyles>`.
13+
For details on the input data see the upstream GMT documentation
14+
at https://docs.generic-mapping-tools.org/latest/plot.html#s.
15+
Furthermore, there are so-called *line fronts*, which are often
16+
used to plot fault lines, subduction zones, or weather fronts;
17+
for details see the
18+
:doc:`Line fronts example </gallery/lines/linefronts>`.
19+
"""
20+
21+
22+
import numpy as np
23+
import pygmt
24+
25+
# Generate a two-point line for plotting
26+
x = np.array([1, 4])
27+
y = np.array([24, 24])
28+
29+
fig = pygmt.Figure()
30+
fig.basemap(region=[0, 10, 0, 24], projection="X15c", frame="+tDecorated Lines")
31+
32+
# Plot different decorated lines
33+
for decoline in [
34+
# Line with circles ("c") of 0.5 centimeters radius in distance of
35+
# 1 centimeter
36+
"~d1c:+sc0.5c",
37+
# Adjust thickness, color, and style of the outline via "+p"
38+
# Here, we plot a 1-point thick, blue, dashed outline
39+
"~d1c:+sc0.5c+p1p,blue,dashed",
40+
# Add a fill color using "+g" with the desired color
41+
"~d1c:+sc0.5c+glightblue",
42+
# To use a pattern as fill append "p" and give the pattern number
43+
"~d1c:+sc0.5c+gp8+p1p,blue",
44+
# Line with triangles ("t")
45+
"~d1c:+st0.5c+gtan+p1p,black",
46+
# Line with inverse triangles with a size of 0.3 centimeters in a
47+
# distance of 0.4 centimeters
48+
"~d0.4c:+si0.3c+gtan+p1p,black",
49+
# Line with squares ("s") with a size of 0.7 centimeters in a distance of
50+
# 1 centimeter
51+
"~d1c:+ss0.7c+gtan+p1p,black",
52+
# Shift symbols using "+n" in x and y directions relative to the baseline
53+
"~d1c:+sd0.5c+gtan+p1p,black+n-0.2c/0.1c",
54+
# Give the number of equally spaced symbols by using "n" instead of "d"
55+
"~n6:+sn0.5c+gtan+p1p,black",
56+
# Use upper-case "N" to have symbols at the start and end of the line
57+
"~N6:+sh0.5c+gtan+p1p,black",
58+
# Suppress the baseline by appending "+i"
59+
"~d1c:+sg0.5c+gtan+p1p,black+i",
60+
# To only plot a symbol at the start of the line use "N-1"
61+
"~N-1:+sp0.2c+gblack",
62+
# To only plot a symbol at the end of the line use "N+1"
63+
"~N+1:+sp0.2c+gblack",
64+
# Line with stars ("a")
65+
"~d1c:+sa0.5c+ggold+p1p,black",
66+
# Line with crosses ("x")
67+
"~d1c:+sx0.5c+p2p,red",
68+
# Line with (vertical) lines or bars ("y")
69+
"~d0.5c:+sy0.5c+p5p,brown",
70+
# Use custom symbol ("k") "squaroid" with a size of 0.5 centimeters
71+
"~d1c:+sksquaroid/0.5c+ggray+p1p,black",
72+
]:
73+
y = y - 1.2 # Move current line down
74+
fig.plot(x=x, y=y, style=decoline, pen="1.25p,black")
75+
fig.text(
76+
x=x[-1],
77+
y=y[-1],
78+
text=decoline,
79+
font="Courier-Bold",
80+
justify="ML",
81+
offset="0.75c/0c",
82+
)
83+
84+
fig.show()

0 commit comments

Comments
 (0)