Skip to content

Commit cbb7861

Browse files
Advanced tutorial on legends: Add example for adjusting line spacing (#4265)
1 parent 15b6d94 commit cbb7861

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

examples/tutorials/advanced/legends.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444

4545

4646
# %%
47-
# Adjust the position
48-
# -------------------
47+
# Adjust position and line spacing
48+
# --------------------------------
4949
#
5050
# Use the ``position`` parameter to adjust the position of the legend. Note, no box is
51-
# drawn by default if ``position`` is used.
51+
# drawn by default if ``position`` is used
5252

5353
fig = pygmt.Figure()
54-
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
54+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rltb")
5555

5656
fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle")
5757
fig.plot(x=1, y=0, style="t0.3c", fill="pink", pen="black", label="pink triangle")
@@ -61,12 +61,23 @@
6161
# and 0.2 centimeters in the x- and y-directions, respectively.
6262
fig.legend(position=Position("TL", offset=(0.3, 0.2)))
6363

64+
fig.shift_origin(xshift="w+1c")
65+
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame="rltb")
66+
67+
fig.plot(x=0, y=0, style="c0.25c", fill="orange", label="orange circle")
68+
fig.plot(x=1, y=0, style="t0.3c", fill="pink", pen="black", label="pink triangle")
69+
fig.plot(x=[-3, 3], y=[-2, -2], pen="darkred", label="darkred line")
70+
71+
# Use a line spacing factor of 1.5
72+
fig.legend(position=Position("TL", offset=(0.3, 0.2)), line_spacing=1.5)
73+
6474
fig.show()
6575

6676

6777
# %%
6878
# Add a box
6979
# ---------
80+
7081
# Use the ``box`` parameter for adjusting the box around the legend.
7182

7283
fig = pygmt.Figure()

0 commit comments

Comments
 (0)