-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple legend columns #2603
Comments
I agree that it would be nice to be able to specify the number of columns directly via the For a legend with multiple columns, users have to write a specific input file instead of using the
This file is passed to the fig = pygmt.Figure()
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(spec="legend_horizontal.txt", position="JTR+jTR+w7.5c+o0.2c", box=True)
fig.show()
# fig.savefig(fname="legend_horizontal.png") |
Thanks,this works at present. |
For auto legend, yes, only one column is supported I think.
There was a suggestion to allow |
I was wrong, it's possible to create multi-column legends for auto-legends. I though there should be a modifier for # 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") |
Description of the desired feature
PyGMT does not support displaying legends in multiple columns, which is usually used when the items to plot have a large number. For instance, the following script would show the legend in two columns.
Are you willing to help implement and maintain this feature?
No
The text was updated successfully, but these errors were encountered: