简体   繁体   中英

how to change legend font size of FacetGrid plot?

I am trying to plot histogram using sns.displot() with hue. I am trying to adjust legend size of each histogram using ax.get_legend() or plt.legend(). It tells me there is no handle for legend for facegrid. Here is the plot. Thanks

g=sns.displot(data,x=x,kind='hist', fill=True, hue=hue,palette=sns.color_palette('bright')[:4], height=15, aspect=1.5)

在此处输入图片说明

You can access the legend from the FacetGrid that sns.displot returns with FacetGrid.legend . Then you can modify the text elements like so:

import seaborn as sns

tips = sns.load_dataset("tips")

g = sns.displot(data=tips, x="total_bill", hue="day")

# Legend title
g.legend.get_title().set_fontsize(20)

# Legend texts
for text in g.legend.texts:
    text.set_fontsize(20)

使用更大的图例文本进行显示

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM