From 4d0a717f27f9cbb11ba412c85874db1c2ca22f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 10 Dec 2025 20:26:21 +0100 Subject: [PATCH 1/5] Add code for adjusting line spacing via +l of position --- examples/tutorials/advanced/legends.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/tutorials/advanced/legends.py b/examples/tutorials/advanced/legends.py index 1870e3a87d9..7c2b55937e7 100644 --- a/examples/tutorials/advanced/legends.py +++ b/examples/tutorials/advanced/legends.py @@ -44,12 +44,15 @@ # %% -# Adjust the position -# ------------------- +# Adjust position and line spacing +# -------------------------------- # # Use the ``position`` parameter to adjust the position of the legend. Add an offset via -# **+o** for the x- and y-directions. Additionally append **+w** to adjust the width -# of the legend. Note, no box is drawn by default if ``position`` is used. +# **+o** for the x- and y-directions. Additionally append **+w** to adjust the width of +# the legend. Note, no box is drawn by default if ``position`` is used. Additionally, +# the ``position`` parameter allows to adjust the line spacing between the legend +# entries. Use the **+l** modifier to change the line spacing factor in units of the +# current font size [Default is 1.1]. fig = pygmt.Figure() fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True) @@ -63,12 +66,23 @@ # respectively. fig.legend(position="jTL+o0.3c/0.2c") +fig.shift_origin(xshift="w+0.5c") +fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rltb") + +fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle") +fig.plot(x=1, y=0, style="t0.3c", fill="pink", pen="black", label="pink triangle") +fig.plot(x=[-3, 3], y=[-2, -2], pen="darkred", label="darkred line") + +# Use a line spacing factor of 1.5 +fig.legend(position="jTL+o0.3c/0.2c+l1.5") + fig.show() # %% # Add a box # --------- +# # Use the ``box`` parameter for adjusting the box around the legend. The outline of the # box can be adjusted by appending **+p**. Append **+g** to fill the legend with a color # (or pattern) [Default is no fill]. The default of ``position`` is preserved. @@ -157,4 +171,4 @@ fig.show() -# sphinx_gallery_thumbnail_number = 4 +# sphinx_gallery_thumbnail_number = 5 From eaa90d97f523ab5a2f53cef2ae959b4fe7d1d089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 10 Dec 2025 22:07:58 +0100 Subject: [PATCH 2/5] Adjust thumbnail number --- examples/tutorials/advanced/legends.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/legends.py b/examples/tutorials/advanced/legends.py index 7c2b55937e7..ea73d67d79d 100644 --- a/examples/tutorials/advanced/legends.py +++ b/examples/tutorials/advanced/legends.py @@ -171,4 +171,4 @@ fig.show() -# sphinx_gallery_thumbnail_number = 5 +# sphinx_gallery_thumbnail_number = 4 From c61f29009dc3d21a8c3412ed656ae6f573c77d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 10 Dec 2025 22:08:36 +0100 Subject: [PATCH 3/5] Use default frame --- examples/tutorials/advanced/legends.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/legends.py b/examples/tutorials/advanced/legends.py index ea73d67d79d..4fefa45f77f 100644 --- a/examples/tutorials/advanced/legends.py +++ b/examples/tutorials/advanced/legends.py @@ -67,7 +67,7 @@ fig.legend(position="jTL+o0.3c/0.2c") fig.shift_origin(xshift="w+0.5c") -fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rltb") +fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True) fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle") fig.plot(x=1, y=0, style="t0.3c", fill="pink", pen="black", label="pink triangle") From f03ecf0375426eed0c3d8f2a12a7ba7c8a1b3c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 10 Dec 2025 22:47:27 +0100 Subject: [PATCH 4/5] Adjust spaces between plots --- examples/tutorials/advanced/legends.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/legends.py b/examples/tutorials/advanced/legends.py index 4fefa45f77f..e73450249e9 100644 --- a/examples/tutorials/advanced/legends.py +++ b/examples/tutorials/advanced/legends.py @@ -66,7 +66,7 @@ # respectively. fig.legend(position="jTL+o0.3c/0.2c") -fig.shift_origin(xshift="w+0.5c") +fig.shift_origin(xshift="w+1c") fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True) fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle") From 120a500ef2880c279734a6433b053ecaf8f12556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 10 Dec 2025 22:50:10 +0100 Subject: [PATCH 5/5] Remove frame --- examples/tutorials/advanced/legends.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tutorials/advanced/legends.py b/examples/tutorials/advanced/legends.py index e73450249e9..b3991bf1e41 100644 --- a/examples/tutorials/advanced/legends.py +++ b/examples/tutorials/advanced/legends.py @@ -55,7 +55,7 @@ # current font size [Default is 1.1]. fig = pygmt.Figure() -fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True) +fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rltb") fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle") fig.plot(x=1, y=0, style="t0.3c", fill="pink", pen="black", label="pink triangle") @@ -67,7 +67,7 @@ fig.legend(position="jTL+o0.3c/0.2c") fig.shift_origin(xshift="w+1c") -fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True) +fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rltb") fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle") fig.plot(x=1, y=0, style="t0.3c", fill="pink", pen="black", label="pink triangle")