How to change a figure's size in Python Seaborn package

前端 未结 6 1716
情深已故
情深已故 2020-12-05 04:32

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

相关标签:
6条回答
  • 2020-12-05 05:09

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

    sns.set(rc={'figure.figsize':(20,10)})
    
    0 讨论(0)
  • 2020-12-05 05:17

    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.

    0 讨论(0)
  • 2020-12-05 05:18

    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)
    
    0 讨论(0)
  • 2020-12-05 05:28

    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)
    
    0 讨论(0)
  • 2020-12-05 05:31

    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.

    0 讨论(0)
  • 2020-12-05 05:35

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

    plt.rcParams['figure.figsize']=(10,10)
    
    0 讨论(0)
提交回复
热议问题