43

I'm having trouble increasing the size of my plot figures using Seaborn (imported as sns). I'm using sns.pairplot to plot columns of a data frame against one another.

    %matplotlib inline
    plt.rcParams['figure.figsize']=10,10
    columns=list(df.columns.values)
    g=sns.pairplot(df, kind='reg', x_vars=columns,y_vars = ['Column 1'])

The plots populate with data just fine, but the figure size is too small.

I thought plot.rCParams['figure.figsize'] would control how large the figure is, but it doesn't seem to take effect. I've tried a few different suggestions from online boards, but nothing seems to work.

Chris Tang
  • 567
  • 7
  • 18
Vikram Josyula
  • 1,373
  • 4
  • 12
  • 15
  • 2
    Did you try the `size` parameter in `pairplot`? – mwaskom Oct 31 '15 at 00:36
  • Tried setting size=5 in pairplot to make the images bigger but didn't seem to take effect. I think the problem is that seaborn is trying to place all 10 plots into a single row adjascent to one another, and that makes it too large for the screen unless the plots are shrunk down. I was able to get this to work by plotting the data frame columns separately, but I figured seaborn would have a way to subplot the data frame columns onto different rows automatically without shrinking them down. – Vikram Josyula Nov 01 '15 at 18:28
  • are you viewing these in a notebook? save them as images and i promise they'll be bigger with `size=5` – Paul H Nov 02 '15 at 05:56
  • Do NOT use `size`. It's a deprecated parameter. Use `height` instead. – MERose Apr 13 '20 at 15:13

7 Answers7

61

sns.pairplot "Returns the underlying PairGrid instance for further tweaking" ...for instance changing the figure size:

g=sns.pairplot(df, kind='reg', x_vars=columns,y_vars = ['Column 1'])
g.fig.set_size_inches(15,15)
Martin Alexandersson
  • 1,269
  • 10
  • 12
  • 1
    Interesting this seems to shrink the size of the plot inside the window, but doesn't shrink the window itself. So i have this massive window now with empty space, and then a small figure in the bottom left. What do you think? – Chris Browne Apr 13 '20 at 09:08
  • I'm not sure why, but doing that doesn't change anything for me... I can try `g.fig.set_size_inches(25,25)` or any other number but nothing will change... I tried with and without `%matplotlib inline`... not sure what is happening, any ideas? – guin0x Aug 25 '22 at 09:27
24

In addition to the well working answer by @MartinAnderson, seaborn itself provides the option to set the height of the subplots of the grid. In combination with the aspect this determines the overall size of the figure in dependence of the number of subplots in the grid.

In seaborn <= 0.8.1:

g = sns.pairplot(..., size=10, aspect=0.6)

In seaborn >= 0.9.0:

g = sns.pairplot(..., height=10, aspect=0.6)

Note that this applies to all seaborn functions which generate a figure level grid, like pairplot, relplot, catplot, lmplot and the underlying PairGrid or FacetGrid.

For other seaborn plots, which directly plot to axes, the solutions from How do you change the size of figures drawn with matplotlib? will work fine.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
21

Try to put the size in parenthesis, this does the trick for me:

plt.rcParams['figure.figsize']=(10,10)
maxymoo
  • 35,286
  • 11
  • 92
  • 119
Scarlett Zuo
  • 505
  • 4
  • 5
13

If we would like to change only the height or only the width then you can do

g = sns.pairplot(df, kind='reg', x_vars=columns,y_vars = ['Column 1'])
g.fig.set_figheight(6)
g.fig.set_figwidth(10)
Jeevan
  • 8,532
  • 14
  • 49
  • 67
9

You can use set for style control : https://seaborn.pydata.org/generated/seaborn.set.html

sns.set(rc={'figure.figsize':(20,10)})
  • 2
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. [From Review](/review/low-quality-posts/26211115) – double-beep May 23 '20 at 18:54
4

Reffering to Rahul's question about sns.catplot ( Unable to change the plot size with matplotlib and seaborn )

If you try in jupyter notebook:

plt.figure(figsize=(25,20))
sns.boxplot(x='CriticRating', y='AudienceRating', data=movies)

it is working, but

sns.boxplot(x='CriticRating', y='AudienceRating', data=movies)
plt.figure(figsize=(25,20))

is not working (plot is very small). It's important to add line plt.figure(figsize=(25,20)) before sns.boxplot()and include %matplotlib inline of course in order to display plot in jupyter.

dejanmarich
  • 1,235
  • 10
  • 26
  • This answer works for `boxplot`, but not for any of the plots that create the figure itself like `pairplot` (this question) or `catplot` (the question you link to). – ImportanceOfBeingErnest Jul 20 '18 at 13:28
1

You can use set for style control : https://seaborn.pydata.org/generated/seaborn.set.html

We can accomplish this using sns.set() For example:

sns.set(rc={'figure.figsize':(20,10)})

Though, the preferred syntax is:

sns.set_theme()

NB: sns.set() or sns.set_theme() is a high level command that will set the (parameters) for everything else in your notebook.

sns.set(rc={'figure.figsize':(20,10)}) will set this to be the figure size for everything else in your notebook

Jinef
  • 11
  • 2