-
Notifications
You must be signed in to change notification settings - Fork 234
Add gallery example showing how to adjust line segment ends (caps and joints) #3015
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 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4a379a9
Add draft for 'line_segment_ends' gallery example
yvonnefroehlich 54a33d8
[format-command] fixes
actions-bot 9746048
Fix highlighting
yvonnefroehlich b8883c7
Use f-string to improve code
yvonnefroehlich 4a27968
Use f-string to improve code
yvonnefroehlich 3adf5cc
Merge branch 'main' into add-gallery-line-ends
yvonnefroehlich 5c00f3a
Use plural
yvonnefroehlich bdaf946
Simplify array for line joints
yvonnefroehlich 407749c
Merge branch 'main' into add-gallery-line-ends
yvonnefroehlich dae5726
[format-command] fixes
actions-bot 7e28819
Explain local change of defaults only once
yvonnefroehlich 5072ef8
Reduce explanation for with statement
yvonnefroehlich 9e49812
Reduce explanation for with statement
yvonnefroehlich 15feba7
Merge branch 'main' into add-gallery-line-ends
yvonnefroehlich ddc3305
Add docs
yvonnefroehlich fc44592
Fix typo
yvonnefroehlich e8c30e7
Improve formulation
yvonnefroehlich a21ed9a
Fix typo
yvonnefroehlich 795d570
Improve docs
yvonnefroehlich bd29479
Merge branch 'main' into add-gallery-line-ends
yvonnefroehlich 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,75 @@ | ||
| """ | ||
| Line segment caps and joints | ||
| ============================ | ||
| PyGMT offers different appearances of line segment caps and joints. The desired | ||
| appearance can be set via the GMT default parameters :gmt-term:`PS_LINE_CAP` | ||
| (``"butt"``, ``"round"``, or ``"square"`` [Default]) as well as :gmt-term:`PS_LINE_JOIN` | ||
| (``"bevel"``, ``"round"``, and ``"miter"`` [Default]) and :gmt-term:`PS_MITER_LIMIT` | ||
| (limit on the angle at the mitered joint below which a bevel is applied). | ||
| """ | ||
|
|
||
| # %% | ||
| import numpy as np | ||
| import pygmt | ||
|
|
||
| # Set up dictionary for colors | ||
| dict_col = { | ||
| "round": "green4", | ||
| "square": "steelblue", | ||
| "butt": "orange", | ||
| "miter": "steelblue", | ||
| "bevel": "orange", | ||
| } | ||
|
|
||
| # Create new Figure instance | ||
| fig = pygmt.Figure() | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # Top: PS_LINE_CAP | ||
|
|
||
| # Create sample data | ||
| x = np.array([30, 170]) | ||
| y = np.array([70, 70]) | ||
|
|
||
| fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame="rltb") | ||
|
|
||
| for line_cap in ["butt", "round", "square"]: | ||
| # Change GMT default locally using a context manager | ||
yvonnefroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # The change applies only to the code under the with statement | ||
yvonnefroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with pygmt.config(PS_LINE_CAP=line_cap): | ||
| # Plot dashed line | ||
| color = dict_col[line_cap] | ||
| fig.plot(x=x, y=y, pen=f"10p,{color},20_20:0") | ||
|
|
||
| fig.plot(x=x, y=y, pen="1p") | ||
| fig.plot(x=x, y=y, style="c0.1c", fill="white", pen="0.5p") | ||
| fig.text(text=line_cap, x=x[-1] + 20, y=y[-1], justify="LM") | ||
|
|
||
| y = y - 20 | ||
|
|
||
| fig.shift_origin(yshift="-h") | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # Bottom: PS_LINE_JOIN and PS_MITER_LIMIT | ||
|
|
||
| # Create sample data | ||
| x = np.array([5, 95, 65]) | ||
| y = np.array([10, 70, 10]) | ||
|
|
||
| fig.basemap(region=[0, 260, 0, 100], projection="x1p", frame="rltb") | ||
|
|
||
| for line_join in ["bevel", "round", "miter"]: | ||
| # Change GMT default locally using a context manager | ||
| # The change applies only to the code under the with statement | ||
yvonnefroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with pygmt.config(PS_LINE_JOIN=line_join, PS_MITER_LIMIT=1): | ||
| # Plot solid line | ||
| color = dict_col[line_join] | ||
| fig.plot(x=x, y=y, pen=f"7p,{color},solid") | ||
|
|
||
| fig.plot(x=x, y=y, pen="1p") | ||
| fig.plot(x=x, y=y, style="c0.1c", fill="white", pen="0.5p") | ||
| fig.text(text=line_join, x=x[1] - 10, y=y[1], justify="RB") | ||
|
|
||
| x = x + 75 | ||
|
|
||
| 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.