Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions examples/tutorials/advanced/legends.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,18 @@


# %%
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have a more Pythonic Figure.legend method after #4046

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Set this PR to draft.

# 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")
Expand All @@ -63,12 +66,23 @@
# respectively.
fig.legend(position="jTL+o0.3c/0.2c")

fig.shift_origin(xshift="w+1c")
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.
Expand Down
Loading