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

DOC/Gallery example "Envelope": General improvements #3625

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
36 changes: 13 additions & 23 deletions examples/gallery/lines/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
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"``.
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
# 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],
Expand All @@ -23,7 +23,7 @@
}
)

# Define the same pandas DataFrame but with lower and upper bounds
# Define the same pandas.DataFrame but with lower and upper bounds
df_bound = pd.DataFrame(
data={
"x": [1, 3, 5, 7, 9],
Expand All @@ -34,7 +34,6 @@
)


# Create Figure instance
fig = pygmt.Figure()

# -----------------------------------------------------------------------------
Expand All @@ -55,15 +54,10 @@
)

# 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",
)
fig.plot(data=df_devi, style="c0.2c", pen="1p,gray30", fill="darkgray")

# Shift plot origin 11 centimeters in x direction
fig.shift_origin(xshift="11c")
# Shift plot origin by the figure width ("w") plus 1 centimeter in x direction
fig.shift_origin(xshift="w+1c")

# -----------------------------------------------------------------------------
# Middle
Expand All @@ -77,18 +71,15 @@
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
# 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
fig.shift_origin(xshift="11c")
fig.shift_origin(xshift="w+1c")

# -----------------------------------------------------------------------------
# Right
Expand All @@ -102,7 +93,6 @@
# 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()