How to change figuresize using seaborn factorplot

前端 未结 7 1578
长情又很酷
长情又很酷 2020-11-27 14:19
%pylab inline

import pandas as pd
import numpy as np
import matplotlib as mpl
import seaborn as sns

typessns = pd.DataFrame.from_csv(\'C:/data/testesns.csv\', inde         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 15:15

    Note added in 2019: In modern seaborn versions the size argument has been renamed to height.

    To be a little more concrete:

    %matplotlib inline
    
    import seaborn as sns
    
    exercise = sns.load_dataset("exercise")
    
    # Defaults are size=5, aspect=1
    sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=2, aspect=1)
    sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=4, aspect=1)
    sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=4, aspect=2)
    

    You want to pass in the arguments 'size' or 'aspect' to the sns.factorplot() when constructing your plot.

    Size will change the height, while maintaining the aspect ratio (so it will also also get wider if only size is changed.)

    Aspect will change the width while keeping the height constant.

    The above code should be able to be run locally in an ipython notebook.

    Plot sizes are reduced in these examples to show the effects, and because the plots from the above code were fairly large when saved as png's. This also shows that size/aspect includes the legend in the margin.

    size=2, aspect=1

    size=2, aspect=1

    size=4, aspect=1

    size=4, aspect=1

    size=4, aspect=2

    size=4, aspect=2

    Also, all other useful parameters/arguments and defaults for this plotting function can be viewed with once the 'sns' module is loaded:

    help(sns.factorplot)
    

提交回复
热议问题