mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.63k stars 1.93k forks source link

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

Open adrbmdns opened 7 months ago

adrbmdns commented 7 months ago

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

mwaskom commented 7 months ago

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)
adrbmdns commented 7 months ago

Thanks for responding this quick. The solution works!