From 2841904950291c7fbb49c91796d8ef218137f08f Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 14 Apr 2024 21:40:43 +0200 Subject: [PATCH 01/12] Add first version of curves_area galley example --- examples/gallery/lines/curves_area.py | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 examples/gallery/lines/curves_area.py diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py new file mode 100755 index 00000000000..ec1b7d03af4 --- /dev/null +++ b/examples/gallery/lines/curves_area.py @@ -0,0 +1,59 @@ +""" +Area between curves +------------------- +Using the ``M`` parameter of the :meth:`pygmt.Figure.plot` method it is possible +to fill the area between two curves y_1 and y_2 with color. Different fills (colors +or patterns) can be used for the areas y_1 > y_2 and y_1 < y_2. Optionally, the +curves can be drawn. +""" + +# %% +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 = np.array([x, y1, y2]) +data_tp = data.transpose() + +data_df = pd.DataFrame(data_tp, columns=["x", "y1", "y2"]) + +# ----------------------------------------------------------------------------- +# Set up new Figure instance +fig = gmt.Figure() +fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) + +fig.plot( + data=data_df, + fill="orange", + M="c+gsteelblue+lshort < long", + label="short > long", +) + +fig.legend() + +fig.show() + + +# %% +# Additionally we can draw the curves. + +# Set up new Figure instance +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", + M="c+gp17+p1p,black,dashed", +) + +fig.show() + +# sphinx_gallery_thumbnail_number = 1 From 8a854754fa351973515429e8a9141a6338162337 Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Sun, 14 Apr 2024 20:07:50 +0000 Subject: [PATCH 02/12] [format-command] fixes --- examples/gallery/lines/curves_area.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/gallery/lines/curves_area.py diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py old mode 100755 new mode 100644 From 0ff0c1935f75bdbae810d2b1049aa8ce7c14e517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 11:30:07 +0200 Subject: [PATCH 03/12] Use new parameter name --- examples/gallery/lines/curves_area.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index ec1b7d03af4..8d10760e1b0 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -1,9 +1,9 @@ """ Area between curves ------------------- -Using the ``M`` parameter of the :meth:`pygmt.Figure.plot` method it is possible -to fill the area between two curves y_1 and y_2 with color. Different fills (colors -or patterns) can be used for the areas y_1 > y_2 and y_1 < y_2. Optionally, the +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 with color. Different fills +(colors or patterns) can be used for the areas y1 > y2 and y1 < y2. Optionally, the curves can be drawn. """ @@ -31,7 +31,7 @@ fig.plot( data=data_df, fill="orange", - M="c+gsteelblue+lshort < long", + fill_between="c+gsteelblue+lshort < long", label="short > long", ) @@ -51,7 +51,7 @@ data=data_df, fill="p8", pen="1p,black,solid", - M="c+gp17+p1p,black,dashed", + fill_between="c+gp17+p1p,black,dashed", ) fig.show() From 9548c89f4aeecee6adc47d4a8f7f348e3dcba21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Fri, 10 Apr 2026 12:00:28 +0200 Subject: [PATCH 04/12] Simply creating of pandas dataframe Co-authored-by: Dongdong Tian --- examples/gallery/lines/curves_area.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index 8d10760e1b0..1ae46dd0c8b 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -18,11 +18,7 @@ y1 = np.sin(x * 3) y2 = np.sin(x / 2) -data = np.array([x, y1, y2]) -data_tp = data.transpose() - -data_df = pd.DataFrame(data_tp, columns=["x", "y1", "y2"]) - +data_df = pd.DataFrame({"x": x, "y1": y1, "y2": y2}) # ----------------------------------------------------------------------------- # Set up new Figure instance fig = gmt.Figure() From 7b179aa82c1277efd3fb4f262a53f8121b1dcf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 12:11:31 +0200 Subject: [PATCH 05/12] Adjust intro text --- examples/gallery/lines/curves_area.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index 1ae46dd0c8b..c42c4b804eb 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -2,9 +2,9 @@ Area between curves ------------------- 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 with color. Different fills -(colors or patterns) can be used for the areas y1 > y2 and y1 < y2. Optionally, the -curves can be drawn. +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. """ # %% From aee5fbf555a5a6b7a7b979082bee6eee8e41d82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Fri, 10 Apr 2026 12:13:23 +0200 Subject: [PATCH 06/12] Improve title Co-authored-by: Dongdong Tian --- examples/gallery/lines/curves_area.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index c42c4b804eb..61597fcc457 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -1,6 +1,6 @@ """ -Area between curves -------------------- +Fill Area between curves +------------------------ 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 From 1ee9c2751a1e53aa3bf4237f9ab3cde004cfa398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Fri, 10 Apr 2026 12:14:03 +0200 Subject: [PATCH 07/12] Fix typo --- examples/gallery/lines/curves_area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index 61597fcc457..6c4dbceae35 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -1,5 +1,5 @@ """ -Fill Area between curves +Fill area between curves ------------------------ 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 From 8ddc317482817682df5c5c15174f734c15f0634b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Fri, 10 Apr 2026 12:14:25 +0200 Subject: [PATCH 08/12] Remove seperation line Co-authored-by: Dongdong Tian --- examples/gallery/lines/curves_area.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index 6c4dbceae35..ff4c67b1e01 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -19,8 +19,6 @@ y2 = np.sin(x / 2) data_df = pd.DataFrame({"x": x, "y1": y1, "y2": y2}) -# ----------------------------------------------------------------------------- -# Set up new Figure instance fig = gmt.Figure() fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) From 784bcfcbf032e5cfe94f2285a3126a32bdd07879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 12:17:50 +0200 Subject: [PATCH 09/12] Improve structure --- examples/gallery/lines/curves_area.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index ff4c67b1e01..f5adca6f60f 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -12,13 +12,17 @@ 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 area between the two curves using the ``fill_between`` parameter. + fig = gmt.Figure() fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) From 805f0d6321a1231fdc1f6daea239d0c85eec7dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 16:56:07 +0200 Subject: [PATCH 10/12] Extend intro text --- examples/gallery/lines/curves_area.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index f5adca6f60f..92101c06946 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -5,6 +5,9 @@ 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 +gallery example :doc:`Wiggle along tracks `. + """ # %% From 629f5b80c7830e45ff0bcfca8de65ebca70e4e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 17:33:12 +0200 Subject: [PATCH 11/12] Add comparision with horizontal line via +y - similar to wiggle --- examples/gallery/lines/curves_area.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index 92101c06946..6cdc492b10c 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -7,7 +7,6 @@ be drawn. To plot an anomaly along a track use :meth:`pygmt.Figure.grdlandmask` and see the gallery example :doc:`Wiggle along tracks `. - """ # %% @@ -57,4 +56,21 @@ fig.show() + +# %% +# Compare to a horizontal line. + +# Set up new Figure instance +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", + fill_between="c+gp17+p1p,black,dashed+y0.42", +) + +fig.show() + # sphinx_gallery_thumbnail_number = 1 From 0b222b5d84b32cb487459bc37da64f0b0539b139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 10 Apr 2026 17:54:12 +0200 Subject: [PATCH 12/12] Add comments --- examples/gallery/lines/curves_area.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/gallery/lines/curves_area.py b/examples/gallery/lines/curves_area.py index 6cdc492b10c..33c10791227 100644 --- a/examples/gallery/lines/curves_area.py +++ b/examples/gallery/lines/curves_area.py @@ -23,7 +23,11 @@ # %% -# Fill the area between the two curves using the ``fill_between`` parameter. +# 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 +# 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) @@ -31,8 +35,8 @@ fig.plot( data=data_df, fill="orange", - fill_between="c+gsteelblue+lshort < long", label="short > long", + fill_between="c+gsteelblue+lshort < long", ) fig.legend() @@ -41,9 +45,10 @@ # %% -# Additionally we can draw the curves. +# Additionally to filling the areas, we can draw the curves. Use the ``pen`` +# parameter and the modifier **+p** for ``fill_between`` to set different +# lines for the two curves y1 and y2, respectively. -# Set up new Figure instance fig = gmt.Figure() fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) @@ -58,9 +63,9 @@ # %% -# Compare to a horizontal line. +# To compare a curve y1 to a horizontal line, append **+y** to ``fill_between`` +# and give the desired y-level. -# Set up new Figure instance fig = gmt.Figure() fig.basemap(region=[-10, 10, -5, 5], projection="X15c/5c", frame=True) @@ -68,6 +73,7 @@ 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", )