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 showing how to build an envelope around a curve #2587

Merged
merged 43 commits into from
Jul 24, 2023
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 Jun 27, 2023
1f1260f
Add missing space
yvonnefroehlich Jun 27, 2023
9d29496
Expand introduction text
yvonnefroehlich Jun 27, 2023
01f3450
Use Unix line ending
yvonnefroehlich Jun 27, 2023
f8b1ed9
Fix typo
yvonnefroehlich Jun 27, 2023
185a5df
Improve formulation of comment
yvonnefroehlich Jun 27, 2023
9d0c757
Correct comment
yvonnefroehlich Jun 27, 2023
bbbe9ea
Fix typo
yvonnefroehlich Jun 27, 2023
cfee157
[format-command] fixes
actions-bot Jun 27, 2023
4870ccf
Fix highlighting
yvonnefroehlich Jun 27, 2023
74e8a2f
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jun 28, 2023
281d61b
Use underscores instead of hypens and adjust column names
Jun 28, 2023
ab2d26a
Remove grid and ticks (code review)
yvonnefroehlich Jun 28, 2023
378b2a4
Remove grid and ticks (code review)
yvonnefroehlich Jun 28, 2023
a18763f
Improve frame
yvonnefroehlich Jun 28, 2023
c0c61f8
Fix typo
yvonnefroehlich Jun 29, 2023
7f00b4f
Remove fill
yvonnefroehlich Jun 29, 2023
e08d636
Add case '+b'
yvonnefroehlich Jun 29, 2023
b3ace3f
Fix format - add and remove white spaces
yvonnefroehlich Jun 29, 2023
8fa6693
Fix format - remove white space, add new line at end of file
yvonnefroehlich Jun 29, 2023
506e685
Use '\053' to handle '+b' as string not as a modifier
yvonnefroehlich Jun 30, 2023
8b38f6e
Fix typo
yvonnefroehlich Jun 30, 2023
b2bc65d
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jun 30, 2023
71ca27d
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jul 3, 2023
4f7653f
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jul 7, 2023
79289cd
Fix typo
yvonnefroehlich Jul 10, 2023
a4d1159
Use more specific name for DataFrame for deviations
yvonnefroehlich Jul 10, 2023
7926428
Shorten comment
yvonnefroehlich Jul 10, 2023
85657c8
Add quotation marks
yvonnefroehlich Jul 10, 2023
470ac92
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jul 10, 2023
1afc0ff
Use consistently plural
yvonnefroehlich Jul 10, 2023
ebc931a
Add missing word
yvonnefroehlich Jul 10, 2023
e13f62e
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jul 12, 2023
387ae2a
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jul 13, 2023
4d29008
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jul 14, 2023
b501490
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jul 20, 2023
d772edb
Write in a single line to reduce number of lines
yvonnefroehlich Jul 20, 2023
dfca09a
Write in a single line to reduce number of lines
yvonnefroehlich Jul 20, 2023
a276425
Write in a single line to reduce number of lines
yvonnefroehlich Jul 20, 2023
571bada
Merge branch 'main' into add-gallery-envelope
yvonnefroehlich Jul 21, 2023
3d89b8e
Use hyphen (code review)
yvonnefroehlich Jul 24, 2023
d6b127e
Use hyphen (code review)
yvonnefroehlich Jul 24, 2023
e42b388
Remove word (code review)
yvonnefroehlich Jul 24, 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
107 changes: 107 additions & 0 deletions examples/gallery/lines/envelope.py
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
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
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.
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.
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()