seaborn icon indicating copy to clipboard operation
seaborn copied to clipboard

`sns.relplot()` legend not showing marker `'x'`, `'+'`, '1', '2' etc.

Open adrbmdns opened this issue 1 year ago • 2 comments

This code is from the seaborn tutorial - An introduction to seaborn.

sns.set_theme(style="ticks", font_scale=1.25)
g = sns.relplot(
    data=penguins,
    x="bill_length_mm", y="bill_depth_mm", hue="body_mass_g",
    palette="crest", marker="x", s=100,
)
g.set_axis_labels("Bill length (mm)", "Bill depth (mm)", labelpad=10)
g.legend.set_title("Body mass (g)")
g.figure.set_size_inches(6.5, 4.5)
g.ax.margins(.15)
g.despine(trim=True)

image

In the legend, it doesn't show the marker handle.

But when I change to solid markers marker="." and marker="X", it will show the marker handle in legend. See,

output

adrbmdns avatar May 01 '24 07:05 adrbmdns

Thanks for reporting, hm, looks like the legend artists are inheriting a zero marker edgewidth from somewhere. You can fix it by doing

plt.setp(g.legend.legend_handles, markeredgewidth=1)

mwaskom avatar May 01 '24 11:05 mwaskom

Thanks for responding this quick. The solution works!

adrbmdns avatar May 01 '24 23:05 adrbmdns