Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the font size using seaborn FacetGrid?

Tags:

python

seaborn

I have plotted my data with factorplot in seaborn and get facetgrid object, but still cannot understand how the following attributes could be set in such a plot:

  1. Legend size: when I plot lots of variables, I get very small legends, with small fonts.
  2. Font sizes of y and x labels (a similar problem as above)
like image 863
james pardon Avatar asked Aug 15 '14 14:08

james pardon


People also ask

How do you change the font size on Xticks in Seaborn?

sns. set(font_scale=2) from p-robot will set all the figure fonts. The answer from Kabir Ahuja works because y-labels position is being used as the text.

What is the default font in Seaborn?

fontfamily (str, optional) – Font-family to use, by default “sans-serif”.


2 Answers

You can scale up the fonts in your call to sns.set().

import numpy as np import matplotlib.pyplot as plt import seaborn as sns x = np.random.normal(size=37) y = np.random.lognormal(size=37)  # defaults sns.set() fig, ax = plt.subplots() ax.plot(x, y, marker='s', linestyle='none', label='small') ax.legend(loc='upper left', bbox_to_anchor=(0, 1.1)) 

enter image description here

sns.set(font_scale=5)  # crazy big fig, ax = plt.subplots() ax.plot(x, y, marker='s', linestyle='none', label='big') ax.legend(loc='upper left', bbox_to_anchor=(0, 1.3)) 

enter image description here

like image 80
Paul H Avatar answered Oct 06 '22 00:10

Paul H


The FacetGrid plot does produce pretty small labels. While @paul-h has described the use of sns.set as a way to the change the font scaling, it may not be the optimal solution since it will change the font_scale setting for all plots.

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.factorplot(x, y ...) 
like image 39
achennu Avatar answered Oct 05 '22 23:10

achennu