Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font size of axis labels in seaborn

In seaborn, how can you change just the x and y axis label font size? Instead of using the "set context" method, is there a way to specifically change just the axis labels? Here is my code:

def corrfunc(x, y, **kws):

    r = stats.pearsonr(x, y)[0] ** 2
    ax = plt.gca()
    ax.annotate("r$^2$ = {:.2f}".format(r),
                xy=(.1, .9), xycoords=ax.transAxes, fontsize=16)
    if r > 0.6:
        col = 'g'
    elif r < 0.6:
        col = 'r'
    sns.regplot(x, y, color=col)
    return r

IC_Plot = sns.PairGrid(df_IC, palette=["red"])
IC_Plot.map_offdiag(corrfunc)

IC_Plot.savefig("Save_Pair.png")
like image 370
Suresh Raja Avatar asked Apr 28 '17 00:04

Suresh Raja


People also ask

How do I increase the font size of a label in Seaborn?

Note that the default value for font_scale is 1. By increasing this value, you can increase the font size of all elements in the plot.

How do you change the font in Seaborn?

You could use the seaborn. plotting_context to change the settings for just the current plot: with sns. plotting_context(font_scale=1.5): sns.

How do I change font size in legend in Seaborn?

This is one of the easiest methods to change the font size of any Seaborn legends, in this we just have to pass the parameter of the fontsize which allows us to pass the font-size value and it will change the font size.


1 Answers

The easiest way to change the fontsize of all x- and y- labels in a plot is to use the rcParams property "axes.labelsize" at the beginning of the script, e.g.

plt.rcParams["axes.labelsize"] = 15

You may also set the font size of each individual label

for ax in plt.gcf().axes:
    l = ax.get_xlabel()
    ax.set_xlabel(l, fontsize=15)
like image 158
ImportanceOfBeingErnest Avatar answered Sep 27 '22 20:09

ImportanceOfBeingErnest