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 "Quoted lines" (style="q") #2563

Merged
merged 25 commits into from
Jul 3, 2023
Merged
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e16adc9
Add basic code for example 'Quoted lines'
yvonnefroehlich Jun 4, 2023
e1b174f
[format-command] fixes
actions-bot Jun 4, 2023
95d2e0b
Add more modifications
yvonnefroehlich Jun 4, 2023
80b90e0
Adjust text for '+v'
yvonnefroehlich Jun 4, 2023
2cc430d
Combine and add variations
yvonnefroehlich Jun 4, 2023
4a58ee0
Add comments for 'quoted lines'
yvonnefroehlich Jun 11, 2023
f129f81
Merge branch 'main' into add-gallery-quotedlines
yvonnefroehlich Jun 11, 2023
1680b0b
Formulate introduction
yvonnefroehlich Jun 11, 2023
5038f27
Improve formulations, fix typos
yvonnefroehlich Jun 11, 2023
b6c171c
Rename file to 'quoted_lines.py'
yvonnefroehlich Jun 27, 2023
959bd9d
Improve explanation for curved text
yvonnefroehlich Jun 27, 2023
f7d1782
Merge branch 'main' into add-gallery-quotedlines
yvonnefroehlich Jun 27, 2023
5346721
Fix typo
yvonnefroehlich Jun 27, 2023
a31b98f
Improve comments
yvonnefroehlich Jun 27, 2023
9bafd44
Use consistently 'label'
yvonnefroehlich Jun 27, 2023
ac00146
Add comment for curved labels
yvonnefroehlich Jun 27, 2023
2ac4664
Merge branch 'main' into add-gallery-quotedlines
yvonnefroehlich Jun 28, 2023
37f00dd
Write in a single line to reduce number of lines
yvonnefroehlich Jun 28, 2023
e0d5506
Write in a single line to reduce number of lines
yvonnefroehlich Jun 28, 2023
202587c
Merge branch 'main' into add-gallery-quotedlines
yvonnefroehlich Jun 29, 2023
94870ce
Write in a single line to reduce number of lines
yvonnefroehlich Jun 29, 2023
2081f33
Add explanation for colon
yvonnefroehlich Jun 30, 2023
5736d7c
Fix style (code review)
yvonnefroehlich Jul 2, 2023
c3b0492
Use 'baseline' instead of 'base line' (code review)
yvonnefroehlich Jul 2, 2023
5004897
Merge branch 'main' into add-gallery-quotedlines
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
106 changes: 106 additions & 0 deletions examples/gallery/lines/quoted_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""
Quoted lines
------------
To plot a so-called *quoted line*, i.e., labels along a line
or curve, use the ``style`` parameter of the
:meth:`pygmt.Figure.plot` method with the argument ``"q"`` and the
desired modifiers. This example shows how to adjust the labels.
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.
"""

import numpy as np
import pygmt

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

fig = pygmt.Figure()
fig.basemap(
region=[0, 10, 0, 20],
projection="X15c/15c",
frame="+tQuoted Lines",
)
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

# Plot different quoted lines
for quotedline in [
# Line with labels ("+l") "text" in distance ("d") of 1 centimeter
"qd1c:+ltext",
# Suppress base line by appending "+i"
"qd1c:+ltext+i",
# Give the number of equally spaced labels by using "n" instead of "d"
"qn5:+ltext",
# Use upper-case "N" to have labels at the start and end of the line
"qN5:+ltext",
# To only plot a label at the start of the line use "N-1"
"qN-1:+ltext",
# To only plot a label at the end of the line use "N+1"
"qN+1:+ltext",
# Adjust the justification of the labels via "+j", here Top Center
"qd1c:+ltext+jTC",
# Shift labels using "+n" in x and y directions relative to the base line
"qd1c:+ltext+n-0.5c/0.1c",
# Rotate labels via "+a" (counter-clockwise from horizontal)
"qd1c:+ltext+a20",
# Adjust size, type, and color of the font via "+f"
"qd1c:+ltext+f12p,Times-Bold,red",
# Add a box around the label via "+p"
"qd1c:+ltext+p",
# Adjust thickness, color, and style of the outline
"qd1c:+ltext+p0.5p,blue,dashed",
# Append "+o" to get a box with rounded edges
"qd1c:+ltext+p0.5p,blue+o",
# Adjust the space between label and box in x and y directions via "+c"
"qd1c:+ltext+p0.5p,blue+o+c0.1c/0.1c",
# Give a fill of the box via "+g" together with the desired color
"qd1c:+ltext+gdodgerblue",
]:
y -= 1 # Move current line down
fig.plot(x=x, y=y, pen="1.25p", style=quotedline)
fig.text(
x=x[-1],
y=y[-1],
text=quotedline,
font="Courier-Bold",
justify="ML",
offset="0.75c/0c",
)

fig.show()


###############################################################################
# For curved labels following the line, append ``"+v"`` to the argument passed
# to the `style` parameter.
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

# Generate sinus curve
x = np.arange(0, 10 * np.pi, 0.1)
y = np.sin(0.8 * x)

fig = pygmt.Figure()

fig.basemap(
region=[0, 30, -4, 4],
projection="X10c/5c",
frame=True,
)
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

fig.plot(
x=x,
y=y + 2,
style="qd1.2c:+lstraight text+f5p",
pen="1p,blue",
)
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

fig.plot(
x=x,
y=y - 2,
# Append "+v" to force curved labels
style="qd1.2c:+lcurved text+f5p+v",
pen="1p,blue",
)

fig.show()