Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

python - How to change figuresize using seaborn factorplot

%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', index_col=False, sep=';')

mpl.rc("figure", figsize=(45, 10))
sns.factorplot("MONTH", "VALUE", hue="REGION", data=typessns, kind="box", palette="OrRd");

enter image description here

I always get a small size figure, no matter what size I 've specified in figsize... How to fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...