Skip to content
Merged
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2841904
Add first version of curves_area galley example
yvonnefroehlich Apr 14, 2024
8a85475
[format-command] fixes
actions-bot Apr 14, 2024
35506d6
Merge branch 'main' into add-gallery-area-curves
yvonnefroehlich Apr 18, 2024
af04674
Merge branch 'main' into add-gallery-area-curves
yvonnefroehlich Apr 9, 2026
c3427da
Merge branch 'main' into add-gallery-area-curves
yvonnefroehlich Apr 9, 2026
20d6c08
Merge branch 'main' into add-gallery-area-curves
yvonnefroehlich Apr 10, 2026
0ff0c19
Use new parameter name
yvonnefroehlich Apr 10, 2026
9548c89
Simply creating of pandas dataframe
yvonnefroehlich Apr 10, 2026
7b179aa
Adjust intro text
yvonnefroehlich Apr 10, 2026
aee5fbf
Improve title
yvonnefroehlich Apr 10, 2026
1ee9c27
Fix typo
yvonnefroehlich Apr 10, 2026
8ddc317
Remove seperation line
yvonnefroehlich Apr 10, 2026
784bcfc
Improve structure
yvonnefroehlich Apr 10, 2026
805f0d6
Extend intro text
yvonnefroehlich Apr 10, 2026
629f5b8
Add comparision with horizontal line via +y - similar to wiggle
yvonnefroehlich Apr 10, 2026
0b222b5
Add comments
yvonnefroehlich Apr 10, 2026
87109dd
Merge branch 'main' into add-gallery-area-curves
yvonnefroehlich Apr 10, 2026
83d458d
Fix title underline
yvonnefroehlich Apr 15, 2026
a2814fb
Merge branch 'main' into add-gallery-area-curves
yvonnefroehlich Apr 15, 2026
3253389
Fix typo in method name
yvonnefroehlich Apr 15, 2026
fdb7661
Fix typo in comparison
yvonnefroehlich Apr 15, 2026
d13ca93
Do not import pygmt as gmt
yvonnefroehlich Apr 15, 2026
02db5ee
Fix grammar
yvonnefroehlich Apr 15, 2026
cddc4b9
Rewrapp to 88 chars
yvonnefroehlich Apr 16, 2026
eb28810
Make file name more descriptive
yvonnefroehlich Apr 16, 2026
a70c461
Merge branch 'main' into add-gallery-area-curves
yvonnefroehlich Apr 16, 2026
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
82 changes: 82 additions & 0 deletions examples/gallery/lines/curves_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""
Fill area between curves
------------------------
Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated
Using the ``fill_between`` parameter of the :meth:`pygmt.Figure.plot` method it is
possible to fill the area between two curves y1 and y2. Different fills (colors or
patterns) can be used for the areas y1 > y2 and y1 < y2. Optionally, the curves can
be drawn.
To plot an anomaly along a track use :meth:`pygmt.Figure.grdlandmask` and see the
Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated
gallery example :doc:`Wiggle along tracks </gallery/lines/wiggle>`.
"""

# %%
import numpy as np
import pandas as pd
import pygmt as gmt

# Generate some test data and create a pandas DataFrame
x = np.arange(-10, 10.2, 0.1)
y1 = np.sin(x * 3)
y2 = np.sin(x / 2)

data_df = pd.DataFrame({"x": x, "y1": y1, "y2": y2})


# %%
# Fill the areas between the two curves using the ``fill_between`` parameter.
# Use the ``fill`` parameter and the modifier **+g** for ``fill_between`` to
# set different fills for areas with y1 > y2 and y2 < y1, respectively. Use
Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated
# the ``label`` parameter and the modifier **+l** for ``fill_between`` to
# set the corresponding legend entries.

fig = gmt.Figure()
fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True)

fig.plot(
data=data_df,
fill="orange",
label="short > long",
fill_between="c+gsteelblue+lshort < long",
)

fig.legend()

fig.show()


# %%
# Additionally to filling the areas, we can draw the curves. Use the ``pen``
Comment thread
yvonnefroehlich marked this conversation as resolved.
Outdated
# parameter and the modifier **+p** for ``fill_between`` to set different
# lines for the two curves y1 and y2, respectively.

fig = gmt.Figure()
fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True)

fig.plot(
data=data_df,
fill="p8",
pen="1p,black,solid",
fill_between="c+gp17+p1p,black,dashed",
)

fig.show()


# %%
# To compare a curve y1 to a horizontal line, append **+y** to ``fill_between``
# and give the desired y-level.

fig = gmt.Figure()
fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True)

fig.plot(
data=data_df[["x", "y1"]],
fill="p8",
pen="1p,black,solid",
# Define a horizontal line at y=0.42
fill_between="c+gp17+p1p,black,dashed+y0.42",
)

fig.show()

# sphinx_gallery_thumbnail_number = 1
Loading