From f58c83e7162b97945da5a8f1c510542ebad71970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 14:06:31 +0200 Subject: [PATCH 01/21] Add example for non-co-registered curves --- .../lines/fill_areas_between_curves.py | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index e73d0ba73f4..3093dd4828f 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -3,7 +3,8 @@ ======================== The :meth:`pygmt.Figure.fill_between` method fills 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. +y1 < y2. Optionally, the curves can be drawn. The two curves can be co-registered or +have different x-coordinates. To plot an anomaly along a track use :meth:`pygmt.Figure.wiggle` and see the gallery example :doc:`Wiggle along tracks `. """ @@ -14,7 +15,7 @@ # Generate some test data x = np.arange(-10, 10.2, 0.1) -y1 = np.sin(x * 3) +y1 = np.sin(3 * x) y2 = np.sin(x / 2) @@ -68,4 +69,39 @@ ) fig.show() + +# %% +# Now, we use two non-co-registered curves, e.g., the two curves have different +# x-coordinates. For providing the x-coordinates for the second curve, use +# parameter ``x2``. + +x1 = np.linspace(0, 4, 100) +x2 = np.array( + [0, 0.21, 0.4, 0.63, 0.89, 1.18, 1.45, 1.69, 1.96, 2.26, 2.61, 3.23, 3.49, 4.0] +) +y1 = 0.5 * np.cos(3 * x1) +y2 = 0.5 * np.cos(3 * x2) + +fig = pygmt.Figure() +fig.basemap(region=[0, 4, -1.2, 1.2], projection="X10c/5c", frame=True) + +fig.fill_between( + x=x1, + y=y1, + x2=x2, + y2=y2, + fill="orange", + fill2="steelblue", + pen="1p,darkred", + pen2="1p,darkblue", + label="y1(x1)", + label2="y2(x2)", +) +# Mark sampling points +fig.plot(x=x1, y=y1, style="c0.1c", fill="darkred") +fig.plot(x=x2, y=y2, style="c0.1c", fill="darkblue") + +fig.legend() + + # sphinx_gallery_thumbnail_number = 1 From 78fa90f3dbae7dea423ac8be5a76b91e021da5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 15:47:38 +0200 Subject: [PATCH 02/21] Add fig.show --- examples/gallery/lines/fill_areas_between_curves.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 3093dd4828f..36d9ab9015d 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -75,11 +75,11 @@ # x-coordinates. For providing the x-coordinates for the second curve, use # parameter ``x2``. -x1 = np.linspace(0, 4, 100) +x1 = np.linspace(0, 4, 10) +y1 = 0.5 * np.cos(3 * x1) x2 = np.array( [0, 0.21, 0.4, 0.63, 0.89, 1.18, 1.45, 1.69, 1.96, 2.26, 2.61, 3.23, 3.49, 4.0] ) -y1 = 0.5 * np.cos(3 * x1) y2 = 0.5 * np.cos(3 * x2) fig = pygmt.Figure() @@ -97,11 +97,12 @@ label="y1(x1)", label2="y2(x2)", ) + # Mark sampling points fig.plot(x=x1, y=y1, style="c0.1c", fill="darkred") fig.plot(x=x2, y=y2, style="c0.1c", fill="darkblue") fig.legend() - +fig.show() # sphinx_gallery_thumbnail_number = 1 From 22cf9608f83eaae7b7884efc7af8e7b33f53ea19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 16:21:13 +0200 Subject: [PATCH 03/21] Fix input data --- examples/gallery/lines/fill_areas_between_curves.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 36d9ab9015d..49e74486ad3 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -75,11 +75,9 @@ # x-coordinates. For providing the x-coordinates for the second curve, use # parameter ``x2``. -x1 = np.linspace(0, 4, 10) -y1 = 0.5 * np.cos(3 * x1) -x2 = np.array( - [0, 0.21, 0.4, 0.63, 0.89, 1.18, 1.45, 1.69, 1.96, 2.26, 2.61, 3.23, 3.49, 4.0] -) +x1 = np.linspace(0, 4, 100) +y1 = np.sin(5 * x1) +x2 = np.array([0, 0.21, 0.4, 0.63, 0.89, 1.18, 1.45, 1.69, 1.96, 2.26, 2.61, 3.23, 3.49, 4.0]) y2 = 0.5 * np.cos(3 * x2) fig = pygmt.Figure() From 71ff233534dcdb9a74ef1bd58abb012546b205a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 16:51:42 +0200 Subject: [PATCH 04/21] Adjust input data --- .../gallery/lines/fill_areas_between_curves.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 49e74486ad3..b95e010f807 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -75,13 +75,13 @@ # x-coordinates. For providing the x-coordinates for the second curve, use # parameter ``x2``. -x1 = np.linspace(0, 4, 100) -y1 = np.sin(5 * x1) -x2 = np.array([0, 0.21, 0.4, 0.63, 0.89, 1.18, 1.45, 1.69, 1.96, 2.26, 2.61, 3.23, 3.49, 4.0]) -y2 = 0.5 * np.cos(3 * x2) +x1 = np.arange(-10, 10.2, 0.2) +y1 = np.sin(2 * x) +x2 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) +y2 = 0.5 * np.cos(2 * x2) fig = pygmt.Figure() -fig.basemap(region=[0, 4, -1.2, 1.2], projection="X10c/5c", frame=True) +fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) fig.fill_between( x=x1, @@ -90,15 +90,15 @@ y2=y2, fill="orange", fill2="steelblue", - pen="1p,darkred", - pen2="1p,darkblue", + pen="1p,darkred,solid", + pen2="1p,darkblue,solid", label="y1(x1)", label2="y2(x2)", ) # Mark sampling points -fig.plot(x=x1, y=y1, style="c0.1c", fill="darkred") -fig.plot(x=x2, y=y2, style="c0.1c", fill="darkblue") +fig.plot(x=x1, y=y1, style="c0.1c", fill="magenta") +fig.plot(x=x2, y=y2, style="c0.1c", fill="cyan") fig.legend() fig.show() From 01217f3b3f9d53a940a184bb93e4f7fa3c7adb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 16:55:34 +0200 Subject: [PATCH 05/21] Fix code style - maybe better exception here --- .../lines/fill_areas_between_curves.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index b95e010f807..432e0aebaba 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -77,7 +77,30 @@ x1 = np.arange(-10, 10.2, 0.2) y1 = np.sin(2 * x) -x2 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) +x2 = np.array( + [ + -10, + -8.21, + -7.4, + -6.63, + -5.89, + -4.18, + -3.45, + -2.69, + -1.96, + 0.26, + 1.61, + 2.23, + 3.49, + 4.0, + 5.28, + 6.79, + 7.12, + 8.25, + 9.13, + 10, + ] +) y2 = 0.5 * np.cos(2 * x2) fig = pygmt.Figure() From 4b4a5f1ad8a3a9ac64cf50d21b22208392615d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 17:00:44 +0200 Subject: [PATCH 06/21] Fix typo in code --- examples/gallery/lines/fill_areas_between_curves.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 432e0aebaba..7324927827b 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -76,7 +76,7 @@ # parameter ``x2``. x1 = np.arange(-10, 10.2, 0.2) -y1 = np.sin(2 * x) +y1 = np.sin(2 * x1) x2 = np.array( [ -10, From 545fcdeb6e69ddd6eb36987a171e590a2987b138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 18:59:24 +0200 Subject: [PATCH 07/21] Adjust region, color and y2 curve --- examples/gallery/lines/fill_areas_between_curves.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 7324927827b..f61eece705f 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -25,7 +25,7 @@ # ``label`` and ``label2`` parameters to set the corresponding legend entries. fig = pygmt.Figure() -fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) +fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) fig.fill_between( x=x, y=y1, y2=y2, fill="orange", fill2="steelblue", label="y1(x)", label2="y2(x)" @@ -39,7 +39,7 @@ # ``pen2`` parameters to set different lines for the two curves y1 and y2, respectively. fig = pygmt.Figure() -fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) +fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) fig.fill_between( x=x, y=y1, @@ -56,7 +56,7 @@ # To compare a curve y1 to a horizontal line, pass the desired y-level to ``y2``. fig = pygmt.Figure() -fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) +fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) fig.fill_between( x=x, @@ -101,10 +101,10 @@ 10, ] ) -y2 = 0.5 * np.cos(2 * x2) +y2 = 0.5 * np.cos(x2 / 2) fig = pygmt.Figure() -fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) +fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) fig.fill_between( x=x1, @@ -120,7 +120,7 @@ ) # Mark sampling points -fig.plot(x=x1, y=y1, style="c0.1c", fill="magenta") +fig.plot(x=x1, y=y1, style="c0.1c", fill="pink") fig.plot(x=x2, y=y2, style="c0.1c", fill="cyan") fig.legend() From ed0d978999d45a4acd8740875e4c9068088e6f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 19:22:54 +0200 Subject: [PATCH 08/21] Include 'legend-pen' --- examples/gallery/lines/fill_areas_between_curves.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index f61eece705f..c7cfd11c5dd 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -117,6 +117,7 @@ pen2="1p,darkblue,solid", label="y1(x1)", label2="y2(x2)", + # legend_pen="5p", ) # Mark sampling points From 7b12e51954deaa7047d3dce1bb902539ea0ab4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 19:47:25 +0200 Subject: [PATCH 09/21] Exclude line length limit locally --- .../lines/fill_areas_between_curves.py | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index c7cfd11c5dd..b835f95ef18 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -77,30 +77,7 @@ x1 = np.arange(-10, 10.2, 0.2) y1 = np.sin(2 * x1) -x2 = np.array( - [ - -10, - -8.21, - -7.4, - -6.63, - -5.89, - -4.18, - -3.45, - -2.69, - -1.96, - 0.26, - 1.61, - 2.23, - 3.49, - 4.0, - 5.28, - 6.79, - 7.12, - 8.25, - 9.13, - 10, - ] -) +x2 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10,]) # noqa: E501 y2 = 0.5 * np.cos(x2 / 2) fig = pygmt.Figure() From 4e6510f78dd76d30c2e987fc0e273ed642152132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 20:27:06 +0200 Subject: [PATCH 10/21] Try using random numbers --- examples/gallery/lines/fill_areas_between_curves.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index b835f95ef18..60b7020a3a2 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -77,7 +77,10 @@ x1 = np.arange(-10, 10.2, 0.2) y1 = np.sin(2 * x1) -x2 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10,]) # noqa: E501 +# Line limit still applies +x2 = np.array([-9, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 9]) # noqa: E501 +# Partly Segmentation fault problem (at least on Windows) +x2 = np.sort((np.random.rand(20) - 0.5) * 20) y2 = 0.5 * np.cos(x2 / 2) fig = pygmt.Figure() From cb6b6fcd8b92cb697d433abc187dc4c1e93724c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 20:32:49 +0200 Subject: [PATCH 11/21] Change back to manual list array for y2 --- examples/gallery/lines/fill_areas_between_curves.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 60b7020a3a2..a394ea051dd 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -77,10 +77,10 @@ x1 = np.arange(-10, 10.2, 0.2) y1 = np.sin(2 * x1) -# Line limit still applies -x2 = np.array([-9, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 9]) # noqa: E501 # Partly Segmentation fault problem (at least on Windows) x2 = np.sort((np.random.rand(20) - 0.5) * 20) +# Line limit still applies +x2 = np.array([-9, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 9]) # noqa: E501 y2 = 0.5 * np.cos(x2 / 2) fig = pygmt.Figure() From b5668766125faa07449f2724890f61ee0e2d88b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 21:03:42 +0200 Subject: [PATCH 12/21] Use complete plotting x region --- examples/gallery/lines/fill_areas_between_curves.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index a394ea051dd..6ceac2c3978 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -80,7 +80,7 @@ # Partly Segmentation fault problem (at least on Windows) x2 = np.sort((np.random.rand(20) - 0.5) * 20) # Line limit still applies -x2 = np.array([-9, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 9]) # noqa: E501 +x2 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) # noqa: E501 y2 = 0.5 * np.cos(x2 / 2) fig = pygmt.Figure() From 1ea695d78a0db191bead4f813b27829875f88033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 24 Jun 2026 22:21:40 +0200 Subject: [PATCH 13/21] Use consistent curves --- examples/gallery/lines/fill_areas_between_curves.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 6ceac2c3978..4f0b39f0924 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -76,12 +76,12 @@ # parameter ``x2``. x1 = np.arange(-10, 10.2, 0.2) -y1 = np.sin(2 * x1) +y1 = np.sin(3 * x1) # Partly Segmentation fault problem (at least on Windows) x2 = np.sort((np.random.rand(20) - 0.5) * 20) # Line limit still applies x2 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) # noqa: E501 -y2 = 0.5 * np.cos(x2 / 2) +y2 = np.sin(x2 / 2) fig = pygmt.Figure() fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) From 208df32fb743b5dd93a1dc012a1be72e3e829d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 25 Jun 2026 08:03:35 +0200 Subject: [PATCH 14/21] Use 'legend_pen' --- examples/gallery/lines/fill_areas_between_curves.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 4f0b39f0924..af4ed662046 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -73,7 +73,9 @@ # %% # Now, we use two non-co-registered curves, e.g., the two curves have different # x-coordinates. For providing the x-coordinates for the second curve, use -# parameter ``x2``. +# parameter ``x2``. Via the ``legend_pen`` parameter the appearence in the legend +# can be changed to draw the legend entries as colored lines (using the fill colors) +# instead of filled boxes. x1 = np.arange(-10, 10.2, 0.2) y1 = np.sin(3 * x1) @@ -97,7 +99,7 @@ pen2="1p,darkblue,solid", label="y1(x1)", label2="y2(x2)", - # legend_pen="5p", + legend_pen="5p", ) # Mark sampling points From 38a2f84bae54b72bc68e3655eff89ae6746e067c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 25 Jun 2026 08:56:24 +0200 Subject: [PATCH 15/21] Restructure example --- .../lines/fill_areas_between_curves.py | 72 ++++++++----------- 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index af4ed662046..4efd5ee5c79 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -5,6 +5,13 @@ y2. Different fills (colors or patterns) can be used for the areas y1 > y2 and y1 < y2. Optionally, the curves can be drawn. The two curves can be co-registered or have different x-coordinates. + +For filling the areas between the two curves use the ``fill`` and ``fill2`` parameters +to set different fills for areas with y1 > y2 and y1 < y2, respectively. Use the ``label`` +and ``label2`` parameters to set the corresponding legend entries. In addition to filling +the areas, we can draw the curves. Use the ``pen`` and ``pen2`` parameters to set different +lines for the two curves y1 and y2, respectively. + To plot an anomaly along a track use :meth:`pygmt.Figure.wiggle` and see the gallery example :doc:`Wiggle along tracks `. """ @@ -14,36 +21,27 @@ import pygmt # Generate some test data -x = np.arange(-10, 10.2, 0.1) +x = np.arange(-10, 10.2, 0.2) y1 = np.sin(3 * x) y2 = np.sin(x / 2) - -# %% -# Fill the areas between the two curves. Use the ``fill`` and ``fill2`` parameters to -# set different fills for areas with y1 > y2 and y1 < y2, respectively. Use the -# ``label`` and ``label2`` parameters to set the corresponding legend entries. - -fig = pygmt.Figure() -fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) - -fig.fill_between( - x=x, y=y1, y2=y2, fill="orange", fill2="steelblue", label="y1(x)", label2="y2(x)" -) -fig.legend() -fig.show() +# Partly Segmentation fault problem (at least on Windows) +x3 = np.sort((np.random.rand(20) - 0.5) * 20) +# Line limit still applies +x3 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) # noqa: E501 +y3 = np.sin(x3 / 2) # %% -# In addition to filling the areas, we can draw the curves. Use the ``pen`` and -# ``pen2`` parameters to set different lines for the two curves y1 and y2, respectively. +# To compare a curve y1(x) to a horizontal line, pass the desired y-level to ``y2``. fig = pygmt.Figure() fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) + fig.fill_between( x=x, y=y1, - y2=y2, + y2=0.42, fill="p8", fill2="p17", pen="1p,black,solid", @@ -53,20 +51,16 @@ # %% -# To compare a curve y1 to a horizontal line, pass the desired y-level to ``y2``. +# To compare two co-registered curves y1(x) and y2(x) pass a sequence with the same length +# as the inputs for ``x`` and ``y`` to ``y2``. fig = pygmt.Figure() fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) fig.fill_between( - x=x, - y=y1, - y2=0.42, - fill="p8", - fill2="p17", - pen="1p,black,solid", - pen2="1p,black,dashed", + x=x, y=y1, y2=y2, fill="orange", fill2="steelblue", label="y1(x)", label2="y2(x)" ) +fig.legend() fig.show() @@ -77,36 +71,28 @@ # can be changed to draw the legend entries as colored lines (using the fill colors) # instead of filled boxes. -x1 = np.arange(-10, 10.2, 0.2) -y1 = np.sin(3 * x1) -# Partly Segmentation fault problem (at least on Windows) -x2 = np.sort((np.random.rand(20) - 0.5) * 20) -# Line limit still applies -x2 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) # noqa: E501 -y2 = np.sin(x2 / 2) - fig = pygmt.Figure() fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) fig.fill_between( - x=x1, + x=x, y=y1, - x2=x2, - y2=y2, + x2=x3, + y2=y3, fill="orange", fill2="steelblue", pen="1p,darkred,solid", pen2="1p,darkblue,solid", - label="y1(x1)", - label2="y2(x2)", - legend_pen="5p", + label="y1(x)", + label2="y3(x3)", + legend_pen=True, ) # Mark sampling points -fig.plot(x=x1, y=y1, style="c0.1c", fill="pink") -fig.plot(x=x2, y=y2, style="c0.1c", fill="cyan") +fig.plot(x=x, y=y1, style="c0.1c", fill="pink") +fig.plot(x=x3, y=y3, style="c0.1c", fill="cyan") fig.legend() fig.show() -# sphinx_gallery_thumbnail_number = 1 +# sphinx_gallery_thumbnail_number = 3 From 41d4ba63ed0b51ea1d588035bf367a3d714dfc91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 25 Jun 2026 09:06:28 +0200 Subject: [PATCH 16/21] Improve intro text --- .../lines/fill_areas_between_curves.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 4efd5ee5c79..950e5b758ae 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -3,17 +3,16 @@ ======================== The :meth:`pygmt.Figure.fill_between` method fills 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. The two curves can be co-registered or -have different x-coordinates. +y1 < y2. The two curves can be co-registered or have different x-coordinates. To plot +an anomaly along a track use :meth:`pygmt.Figure.wiggle` and see the gallery example +:doc:`Wiggle along tracks `. For filling the areas between the two curves use the ``fill`` and ``fill2`` parameters -to set different fills for areas with y1 > y2 and y1 < y2, respectively. Use the ``label`` -and ``label2`` parameters to set the corresponding legend entries. In addition to filling -the areas, we can draw the curves. Use the ``pen`` and ``pen2`` parameters to set different -lines for the two curves y1 and y2, respectively. +to set different fills for the areas with y1 > y2 and y1 < y2, respectively. Use the +``label`` and ``label2`` parameters to set the corresponding legend entries. In addition +to filling the areas, we can draw the outline curves. Use the ``pen`` and ``pen2`` +parameters to set different lines for the two curves y1 and y2, respectively. -To plot an anomaly along a track use :meth:`pygmt.Figure.wiggle` and see the gallery -example :doc:`Wiggle along tracks `. """ # %% @@ -26,7 +25,7 @@ y2 = np.sin(x / 2) # Partly Segmentation fault problem (at least on Windows) -x3 = np.sort((np.random.rand(20) - 0.5) * 20) +x3 = np.sort((np.random.Generator(20) - 0.5) * 20) # Line limit still applies x3 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) # noqa: E501 y3 = np.sin(x3 / 2) @@ -51,8 +50,8 @@ # %% -# To compare two co-registered curves y1(x) and y2(x) pass a sequence with the same length -# as the inputs for ``x`` and ``y`` to ``y2``. +# To compare two co-registered curves y1(x) and y2(x) pass a sequence with the same +# length as the inputs for ``x`` and ``y`` to ``y2``. fig = pygmt.Figure() fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) @@ -69,7 +68,7 @@ # x-coordinates. For providing the x-coordinates for the second curve, use # parameter ``x2``. Via the ``legend_pen`` parameter the appearence in the legend # can be changed to draw the legend entries as colored lines (using the fill colors) -# instead of filled boxes. +# instead of filled and outlined boxes. fig = pygmt.Figure() fig.basemap(region=[-10, 10, -3.5, 3.5], projection="X15c/5c", frame=True) From 18de8be735dd7ffe8a1abbe0cb99f2d2f310effb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 25 Jun 2026 09:12:24 +0200 Subject: [PATCH 17/21] Fix random numbers --- examples/gallery/lines/fill_areas_between_curves.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 950e5b758ae..bb5aace6e31 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -25,7 +25,7 @@ y2 = np.sin(x / 2) # Partly Segmentation fault problem (at least on Windows) -x3 = np.sort((np.random.Generator(20) - 0.5) * 20) +# x3 = np.sort((np.random.rand(20) - 0.5) * 20) # Line limit still applies x3 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) # noqa: E501 y3 = np.sin(x3 / 2) From 47a1d2ec44947756754ce818c9a394526b4b92a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Thu, 25 Jun 2026 10:40:02 +0200 Subject: [PATCH 18/21] Use only one decimal digit for x3 Co-authored-by: Dongdong Tian --- examples/gallery/lines/fill_areas_between_curves.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index bb5aace6e31..36370fe51a6 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -27,7 +27,7 @@ # Partly Segmentation fault problem (at least on Windows) # x3 = np.sort((np.random.rand(20) - 0.5) * 20) # Line limit still applies -x3 = np.array([-10, -8.21, -7.4, -6.63, -5.89, -4.18, -3.45, -2.69, -1.96, 0.26, 1.61, 2.23, 3.49, 4.0, 5.28, 6.79, 7.12, 8.25, 9.13, 10]) # noqa: E501 +x3 = np.array([-10, -8.2, -7.4, -6.6, -5.8, -4.1, -3.4, -2.6, -1.9, 0.2, 1.6, 2.2, 3.4, 4.0, 5.2, 6.7, 7.1, 8.2, 9.1, 10]) # noqa: E501 y3 = np.sin(x3 / 2) From 398f35600e036f2a091cdeb5a0c3ade43b72196b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 25 Jun 2026 11:31:26 +0200 Subject: [PATCH 19/21] Shift and increase step of the curve for other sampling points --- examples/gallery/lines/fill_areas_between_curves.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 36370fe51a6..1b1185df7f4 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -24,10 +24,7 @@ y1 = np.sin(3 * x) y2 = np.sin(x / 2) -# Partly Segmentation fault problem (at least on Windows) -# x3 = np.sort((np.random.rand(20) - 0.5) * 20) -# Line limit still applies -x3 = np.array([-10, -8.2, -7.4, -6.6, -5.8, -4.1, -3.4, -2.6, -1.9, 0.2, 1.6, 2.2, 3.4, 4.0, 5.2, 6.7, 7.1, 8.2, 9.1, 10]) # noqa: E501 +x3 = np.arange(-10, 10.4, 0.5) - 0.15 y3 = np.sin(x3 / 2) From 3a605333b25e9113349aa4146e939981bd97e20f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 25 Jun 2026 11:40:51 +0200 Subject: [PATCH 20/21] Increase sampling --- examples/gallery/lines/fill_areas_between_curves.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 1b1185df7f4..3cff739e100 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -20,11 +20,11 @@ import pygmt # Generate some test data -x = np.arange(-10, 10.2, 0.2) +x = np.arange(-10, 10.2, 0.15) y1 = np.sin(3 * x) y2 = np.sin(x / 2) -x3 = np.arange(-10, 10.4, 0.5) - 0.15 +x3 = np.arange(-10, 10.4, 0.5) - 0.13 y3 = np.sin(x3 / 2) From 6306da116ba4ca556b3032aa90ca0d789c2876f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Thu, 25 Jun 2026 11:50:43 +0200 Subject: [PATCH 21/21] Fix typo --- examples/gallery/lines/fill_areas_between_curves.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/lines/fill_areas_between_curves.py b/examples/gallery/lines/fill_areas_between_curves.py index 3cff739e100..db30e125f5a 100644 --- a/examples/gallery/lines/fill_areas_between_curves.py +++ b/examples/gallery/lines/fill_areas_between_curves.py @@ -63,7 +63,7 @@ # %% # Now, we use two non-co-registered curves, e.g., the two curves have different # x-coordinates. For providing the x-coordinates for the second curve, use -# parameter ``x2``. Via the ``legend_pen`` parameter the appearence in the legend +# parameter ``x2``. Via the ``legend_pen`` parameter the appearance in the legend # can be changed to draw the legend entries as colored lines (using the fill colors) # instead of filled and outlined boxes.