How to increase the font size of the legend in my Seaborn plot?

前端 未结 2 556
长发绾君心
长发绾君心 2020-12-25 14:13

I have the following codes to create a Seaborn strip plot. I am having a hard time figuring out how to increase the font size of the legend appearing in the plot.

         


        
2条回答
  •  被撕碎了的回忆
    2020-12-25 14:36

    Use matplotlib function setp according to this example:

    import seaborn as sns
    import matplotlib.pylab as plt
    sns.set_style("whitegrid")
    tips = sns.load_dataset("tips")
    
    ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)
    plt.setp(ax.get_legend().get_texts(), fontsize='22') # for legend text
    plt.setp(ax.get_legend().get_title(), fontsize='32') # for legend title
    
    plt.show()
    

    Another way is to change font_scale of all graph with plotting_context: http://seaborn.pydata.org/generated/seaborn.plotting_context.html

提交回复
热议问题