-
Notifications
You must be signed in to change notification settings - Fork 235
Add gallery example "Quoted lines" (style="q")
#2563
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
Merged
Merged
Changes from 20 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 e1b174f
[format-command] fixes
actions-bot 95d2e0b
Add more modifications
yvonnefroehlich 80b90e0
Adjust text for '+v'
yvonnefroehlich 2cc430d
Combine and add variations
yvonnefroehlich 4a58ee0
Add comments for 'quoted lines'
yvonnefroehlich f129f81
Merge branch 'main' into add-gallery-quotedlines
yvonnefroehlich 1680b0b
Formulate introduction
yvonnefroehlich 5038f27
Improve formulations, fix typos
yvonnefroehlich b6c171c
Rename file to 'quoted_lines.py'
yvonnefroehlich 959bd9d
Improve explanation for curved text
yvonnefroehlich f7d1782
Merge branch 'main' into add-gallery-quotedlines
yvonnefroehlich 5346721
Fix typo
yvonnefroehlich a31b98f
Improve comments
yvonnefroehlich 9bafd44
Use consistently 'label'
yvonnefroehlich ac00146
Add comment for curved labels
yvonnefroehlich 2ac4664
Merge branch 'main' into add-gallery-quotedlines
yvonnefroehlich 37f00dd
Write in a single line to reduce number of lines
yvonnefroehlich e0d5506
Write in a single line to reduce number of lines
yvonnefroehlich 202587c
Merge branch 'main' into add-gallery-quotedlines
yvonnefroehlich 94870ce
Write in a single line to reduce number of lines
yvonnefroehlich 2081f33
Add explanation for colon
yvonnefroehlich 5736d7c
Fix style (code review)
yvonnefroehlich c3b0492
Use 'baseline' instead of 'base line' (code review)
yvonnefroehlich 5004897
Merge branch 'main' into add-gallery-quotedlines
michaelgrund File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """ | ||
| 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 | ||
| :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.
Outdated
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.
Outdated
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) | ||
|
|
||
| fig.plot(x=x, y=y + 2, style="qd1.2c:+lstraight text+f5p", pen="1p,blue") | ||
|
|
||
| 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() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.