seaborn
seaborn copied to clipboard
`sns.relplot()` legend not showing marker `'x'`, `'+'`, '1', '2' etc.
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)
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,
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)
Thanks for responding this quick. The solution works!