-
Notifications
You must be signed in to change notification settings - Fork 235
Add gallery example showing how to build an envelope around a curve #2587
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 40 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
22c85f6
Add basic code and docs for gallery example 'Envelope'
yvonnefroehlich 1f1260f
Add missing space
yvonnefroehlich 9d29496
Expand introduction text
yvonnefroehlich 01f3450
Use Unix line ending
yvonnefroehlich f8b1ed9
Fix typo
yvonnefroehlich 185a5df
Improve formulation of comment
yvonnefroehlich 9d0c757
Correct comment
yvonnefroehlich bbbe9ea
Fix typo
yvonnefroehlich cfee157
[format-command] fixes
actions-bot 4870ccf
Fix highlighting
yvonnefroehlich 74e8a2f
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich 281d61b
Use underscores instead of hypens and adjust column names
ab2d26a
Remove grid and ticks (code review)
yvonnefroehlich 378b2a4
Remove grid and ticks (code review)
yvonnefroehlich a18763f
Improve frame
yvonnefroehlich c0c61f8
Fix typo
yvonnefroehlich 7f00b4f
Remove fill
yvonnefroehlich e08d636
Add case '+b'
yvonnefroehlich b3ace3f
Fix format - add and remove white spaces
yvonnefroehlich 8fa6693
Fix format - remove white space, add new line at end of file
yvonnefroehlich 506e685
Use '\053' to handle '+b' as string not as a modifier
yvonnefroehlich 8b38f6e
Fix typo
yvonnefroehlich b2bc65d
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich 71ca27d
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich 4f7653f
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich 79289cd
Fix typo
yvonnefroehlich a4d1159
Use more specific name for DataFrame for deviations
yvonnefroehlich 7926428
Shorten comment
yvonnefroehlich 85657c8
Add quotation marks
yvonnefroehlich 470ac92
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich 1afc0ff
Use consistently plural
yvonnefroehlich ebc931a
Add missing word
yvonnefroehlich e13f62e
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich 387ae2a
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich 4d29008
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich b501490
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich d772edb
Write in a single line to reduce number of lines
yvonnefroehlich dfca09a
Write in a single line to reduce number of lines
yvonnefroehlich a276425
Write in a single line to reduce number of lines
yvonnefroehlich 571bada
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich 3d89b8e
Use hyphen (code review)
yvonnefroehlich d6b127e
Use hyphen (code review)
yvonnefroehlich e42b388
Remove word (code review)
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,107 @@ | ||
| """ | ||
| Envelope | ||
| -------- | ||
| The ``close`` parameter of the :meth:`pygmt.Figure.plot` method can be | ||
| used to build a symmetrical or an asymmetrical envelope. The user can | ||
| give either the deviations or the bounds in y direction. For the first | ||
| case append ``"+d"`` or ``"+D"`` and for the latter case ``"+b"``. | ||
| """ | ||
|
|
||
|
|
||
| import pandas as pd | ||
| import pygmt | ||
|
|
||
| # Define a pandas DataFrame with columns for x and y as well as the | ||
| # lower and upper deviations | ||
| df_devi = pd.DataFrame( | ||
| data={ | ||
| "x": [1, 3, 5, 7, 9], | ||
| "y": [0.5, -0.7, 0.8, -0.3, 0.1], | ||
| "y_deviation_low": [0.2, 0.2, 0.3, 0.4, 0.2], | ||
| "y_deviation_upp": [0.1, 0.3, 0.2, 0.4, 0.1], | ||
| } | ||
| ) | ||
|
|
||
| # Define the same pandas DataFrame but with the lower and upper bounds | ||
yvonnefroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| df_bound = pd.DataFrame( | ||
| data={ | ||
| "x": [1, 3, 5, 7, 9], | ||
| "y": [0.5, -0.7, 0.8, -0.3, 0.1], | ||
| "y_bound_low": [0.3, -0.9, 0.5, -0.7, -0.1], | ||
| "y_bound_upp": [0.6, -0.4, 1.1, 0.1, 0.2], | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| # Create Figure instance | ||
| fig = pygmt.Figure() | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # Left | ||
| fig.basemap( | ||
| region=[0, 10, -1.5, 1.5], | ||
| projection="X10c", | ||
| frame=["WSne+tsymmetric deviations +d", "xa2f1", "ya1f0.1"], | ||
| ) | ||
|
|
||
| # Plot a symmetrical envelope based on the deviations ("+d") | ||
| fig.plot( | ||
| data=df_devi, | ||
| close="+d", | ||
| # Fill the envelope in gray color with a transparency of 50 % | ||
| fill="gray@50", | ||
| pen="1p,gray30", | ||
| ) | ||
|
|
||
| # Plot the data points on top | ||
| fig.plot( | ||
| data=df_devi, | ||
| style="c0.2c", # Use circles with a diameter of 0.2 centimeters | ||
| pen="1p,gray30", | ||
| fill="darkgray", | ||
| ) | ||
|
|
||
| # Shift plot origin 11 centimeters in x direction | ||
| fig.shift_origin(xshift="11c") | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # Middle | ||
| fig.basemap( | ||
| region=[0, 10, -1.5, 1.5], | ||
| projection="X10c", | ||
| frame=["WSne+tasymmetric deviations +D", "xa2f1", "yf0.1"], | ||
| ) | ||
|
|
||
| # Plot an asymmetrical envelope based on the deviations ("+D") | ||
| fig.plot( | ||
| data=df_devi, | ||
| fill="gray@50", | ||
| # Add an outline around the envelope | ||
| # Here, a dashed pen ("+p") with 0.5-points thickness and | ||
| # "gray30" color is used | ||
| close="+D+p0.5p,gray30,dashed", | ||
| pen="1p,gray30", | ||
| ) | ||
|
|
||
| # Plot the data points on top | ||
| fig.plot(data=df_devi, style="c0.2c", pen="1p,gray30", fill="darkgray") | ||
|
|
||
| # Shift plot origin 11 centimeters in x direction | ||
yvonnefroehlich marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fig.shift_origin(xshift="11c") | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # Right | ||
| fig.basemap( | ||
| region=[0, 10, -1.5, 1.5], | ||
| projection="X10c", | ||
| # Use "\\053" to handle "+b" as a string not as a modifier | ||
| frame=["wSnE+tbounds \\053b", "xa2f1", "ya1f0.1"], | ||
| ) | ||
|
|
||
| # Plot an envelope based on the bounds ("+b") | ||
| fig.plot(data=df_bound, close="+b+p0.5p,gray30,dashed", pen="1p,gray30") | ||
|
|
||
| # Plot the data points on top | ||
| fig.plot(data=df_bound, style="c0.2c", pen="1p,gray30", fill="darkgray") | ||
|
|
||
| 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.