It’s available in PyGMT, but I did not know this! Thanks a lot @pwessel. That’s great, was really missing this possibility. I though there should be a modifier for legend to force multi-column legends, but the specifications has to be made together with the argument passed to the label parameter of plot.
# Based on Gallery example: https://www.pygmt.org/latest/gallery/embellishments/legend.html#sphx-glr-gallery-embellishments-legend-py
# Last acces: 2023/10/20
import pygmt
fig = pygmt.Figure()
# -----------------------------------------------------------------------------
# Left: Vertical (one column) legend
fig.basemap(projection="x2c", region=[0, 7, 3, 7], frame=True)
fig.plot(
data="@Table_5_11.txt",
style="c0.40c",
fill="lightgreen",
pen="faint",
label="Apples",
)
fig.plot(data="@Table_5_11.txt", pen="1.5p,gray", label="My lines")
fig.plot(data="@Table_5_11.txt", style="t0.40c", fill="orange", label="Oranges")
fig.legend(position="JTR+jTR+o0.2c", box=True)
fig.shift_origin(xshift="+w1c")
# -----------------------------------------------------------------------------
# Right: Horizontal (three columns) legend
fig.basemap(projection="x2c", region=[0, 7, 3, 7], frame=True)
fig.plot(
data="@Table_5_11.txt",
style="c0.40c",
fill="lightgreen",
pen="faint",
# +N sets columns of the legend corresponding to the given number
label="Apples+N3",
)
fig.plot(data="@Table_5_11.txt", pen="1.5p,gray", label="My lines")
fig.plot(data="@Table_5_11.txt", style="t0.40c", fill="orange", label="Oranges")
# For multi-column legends users have to provide the width via +w
fig.legend(position="JTR+jTR+w7c+o0.2c", box=True)
fig.show()
# fig.savefig(fname="multi_col_legend.png")
Output:
