Skip to content

Add Figure.fill_between to fill between two curves#4679

Open
seisman wants to merge 2 commits into
mainfrom
feature/fill_between
Open

Add Figure.fill_between to fill between two curves#4679
seisman wants to merge 2 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

@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_two_coregistered_curves.png
added pygmt/tests/baseline/test_fill_between_y2_scalar.png

Image diff(s)

Details

Added images

  • test_fill_between_two_coregistered_curves.png

  • test_fill_between_y2_scalar.png

Modified images

Path Old New

Report last updated at commit f555308

@seisman seisman added the needs review This PR has higher priority and needs review. label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature needs review This PR has higher priority and needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant