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.