Skip to content

Add Figure.fill_between to fill between two curves - #4679

Merged
seisman merged 15 commits into
mainfrom
feature/fill_between
Jun 20, 2026
Merged

seisman merged 15 commits into
mainfrom
feature/fill_between

Conversation

@seisman

@seisman seisman commented Jun 14, 2026 •

Copy link
Copy Markdown
Member

This PR provides an initial implementation for the Figure.fill_between method, which fills the area between two curves.

The two curves are called y1 and y2 in the docstring. Curve y1 is specified via x/y, and curve 2 is specified via x/y2. Therefore, the two curves must be co-registered. Supporting for curves that are not co-registered can be done by adding a separate parameter x2, which can be done in a future PR.

This PR mainly wraps the plot's -M option. Core options include:

  • -W: pen
  • -G: fill
  • -l: label
  • -M
    • c: y1 and y2 are co-registered
    • s: y1 and y2 are not co-registered [not supported yet]
    • +g: fill2 fill for y2>y1
    • +l: label2 label for y2 curve
    • +p: pen2 pen for y2 curve
    • +r: draw legend entries as lines, rather than filled boxes [it may contains bugs]
    • +y: y2 is a horizontal constant, i.e., y2=0

An working example

import numpy as np
import pygmt

x = np.linspace(0, 2 * np.pi, 200)
fig = pygmt.Figure()
fig.fill_between(
    x=x,
    y=np.sin(2 * x),
    y2=np.sin(3 * x),
    region=[0, 2 * np.pi, -1.2, 1.2],
    projection="X10c/4c",
    frame=True,
    fill="lightblue",
    pen="1p,blue",
    fill2="lightred",
    pen2="1p,red",
)
fig.show()
fill_between

Address #4678

Preview: https://pygmt-dev--4679.org.readthedocs.build/en/4679/api/generated/pygmt.Figure.fill_between.html

@seisman seisman added the feature Brand new feature label Jun 14, 2026
@seisman seisman added this to the 0.19.0 milestone Jun 14, 2026
@github-actions

github-actions Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary of changed images

This is an auto-generated report of images that have changed on the DVC remote

Status Path
added pygmt/tests/baseline/test_fill_between_coregistered.png
added pygmt/tests/baseline/test_fill_between_y2_scalar.png

Image diff(s)

Details

Added images

  • test_fill_between_coregistered.png

  • test_fill_between_y2_scalar.png

Modified images

Path Old New

Report last updated at commit 17fee1f

@seisman seisman added the needs review This PR has higher priority and needs review. label Jun 14, 2026
Comment thread pygmt/src/fill_between.py Resolved
Comment thread pygmt/src/fill_between.py Resolved
Comment thread pygmt/tests/test_fill_between.py Resolved
Co-authored-by: Yvonne Fröhlich <[email protected]>
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Jun 19, 2026
Comment thread pygmt/src/fill_between.py Resolved
Co-authored-by: Yvonne Fröhlich <[email protected]>
@seisman
seisman merged commit 1704f38 into main Jun 20, 2026
24 checks passed
@seisman
seisman deleted the feature/fill_between branch June 20, 2026 03:08
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Jun 20, 2026

This branch was previously deployed

1 inactive deployment
pr-tests — 17fee1f1 Deployed Jun 19, 2026 by seisman via DVC image diff #1398
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants