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 gallery example "Decorated lines" (style="~") #2564

Merged
merged 24 commits into from
Jul 3, 2023
Merged
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8e74fe
Add basic code for example 'decorated lines'
yvonnefroehlich Jun 4, 2023
a10007d
[format-command] fixes
actions-bot Jun 4, 2023
9e100e7
Update introduction text
yvonnefroehlich Jun 4, 2023
b52f8dc
Add missing parameter 'fill'
yvonnefroehlich Jun 4, 2023
911d440
Add comments for 'decorated lines'
yvonnefroehlich Jun 11, 2023
9ae5c75
Fix typos
yvonnefroehlich Jun 11, 2023
ca68344
Merge branch 'main' into add-gallery-decoratedlines
yvonnefroehlich Jun 11, 2023
df37b62
[format-command] fixes
actions-bot Jun 11, 2023
8177bb4
Fix typos
yvonnefroehlich Jun 11, 2023
4804c90
Formulate introduction
yvonnefroehlich Jun 11, 2023
e37fc24
Improve formulations, fix typos
yvonnefroehlich Jun 11, 2023
9dcc489
Improve introduction text
yvonnefroehlich Jun 11, 2023
7a1850f
Rename file to 'decorated_lines.py'
yvonnefroehlich Jun 27, 2023
9e76406
Remove reminder comment
yvonnefroehlich Jun 27, 2023
3c0b33b
Merge branch 'main' into add-gallery-decoratedlines
yvonnefroehlich Jun 27, 2023
9f0b80a
Add missing word
yvonnefroehlich Jun 27, 2023
2ca85c7
Use 'dashed' instead of '-'
yvonnefroehlich Jun 27, 2023
30550aa
Merge branch 'main' into add-gallery-decoratedlines
yvonnefroehlich Jun 28, 2023
34698a4
Merge branch 'main' into add-gallery-decoratedlines
yvonnefroehlich Jun 29, 2023
250834f
Write in a single line to reduce number of lines
yvonnefroehlich Jun 29, 2023
1e36581
Add explanation for colon
yvonnefroehlich Jun 30, 2023
e9fa913
Fix typo (code review)
yvonnefroehlich Jul 2, 2023
d0d7c59
Use 'baseline' instead of 'base line' (code review)
yvonnefroehlich Jul 2, 2023
3fb485f
Merge branch 'main' into add-gallery-decoratedlines
michaelgrund Jul 3, 2023
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
84 changes: 84 additions & 0 deletions examples/gallery/lines/decorated_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
Decorated lines
---------------
To draw a so-called *decorated line*, i.e., symbols along a line
or curve, use the ``style`` parameter of the
:meth:`pygmt.Figure.plot` method with the argument ``"~"`` and the
desired modifiers. A colon (``":"``) is used to separate the
algorithm settings from the symbol information.
This example shows how to adjust the symbols.
Beside the build-in symbols also custom symbols can be used.
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
For modifying the base line via the ``pen`` parameter, see the
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
:doc:`Line styles example </gallery/lines/linestyles>`.
For details on the input data see the upstream GMT documentation
at https://docs.generic-mapping-tools.org/latest/plot.html#s.
Furthermore, there are so-called *line fronts*, which are often
used to plot fault lines, subduction zones, or weather fronts;
for details see the
:doc:`Line fronts example </gallery/lines/linefronts>`.
"""


import numpy as np
import pygmt

# Generate a two-point line for plotting
x = np.array([1, 4])
y = np.array([24, 24])

fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 24], projection="X15c", frame="+tDecorated Lines")

# Plot different decorated lines
for decoline in [
# Line with circles ("c") of 0.5 centimeters radius in distance of
# 1 centimeter
"~d1c:+sc0.5c",
# Adjust thickness, color, and style of the outline via "+p"
# Here, we plot a 1-point thick, blue, dashed outline
"~d1c:+sc0.5c+p1p,blue,dashed",
# Add a fill color using "+g" with the desired color
"~d1c:+sc0.5c+glightblue",
# To use a pattern as fill append "p" and give the pattern number
"~d1c:+sc0.5c+gp8+p1p,blue",
# Line with triangles ("t")
"~d1c:+st0.5c+gtan+p1p,black",
# Line with inverse triangles with a size of 0.3 centimeters in a
# distance of 0.4 centimeters
"~d0.4c:+si0.3c+gtan+p1p,black",
# Line with squares ("s") with a size of 0.7 centimeters in a distance of
# 1 centimeter
"~d1c:+ss0.7c+gtan+p1p,black",
# Shift symbols using "+n" in x and y directions relative to the base line
"~d1c:+sd0.5c+gtan+p1p,black+n-0.2c/0.1c",
# Give the number of equally spaced symbols by using "n" instead of "d"
"~n6:+sn0.5c+gtan+p1p,black",
# Use upper-case "N" to have symbols at the start and end of the line
"~N6:+sh0.5c+gtan+p1p,black",
# Suppress the base line by appending "+i"
"~d1c:+sg0.5c+gtan+p1p,black+i",
# To only plot a symbol at the start of the line use "N-1"
"~N-1:+sp0.2c+gblack",
# To only plot a symbol at the end of the line use "N+1"
"~N+1:+sp0.2c+gblack",
# Line with stars ("a")
"~d1c:+sa0.5c+ggold+p1p,black",
# Line with crosses ("x")
"~d1c:+sx0.5c+p2p,red",
# Line with (vertical) lines or bars ("y")
"~d0.5c:+sy0.5c+p5p,brown",
# Use custom symbol ("k") "squaroid" with a size of 0.5 centimeters
"~d1c:+sksquaroid/0.5c+ggray+p1p,black",
]:
y = y - 1.2 # Move current line down
fig.plot(x=x, y=y, style=decoline, pen="1.25p,black")
fig.text(
x=x[-1],
y=y[-1],
text=decoline,
font="Courier-Bold",
justify="ML",
offset="0.75c/0c",
)

fig.show()