我如何改变我的图像的大小,使其适合打印?

例如,我想使用A4纸,它的尺寸是11.7英寸乘8.27英寸。


当前回答

# Sets the figure size temporarily but has to be set again the next plot
plt.figure(figsize=(18,18))

sns.barplot(x=housing.ocean_proximity, y=housing.median_house_value)
plt.show()

其他回答

你也可以通过将字典传递给rc参数,键为'figure '来设置图形大小。海运集方法中的Figsize ':

import seaborn as sns

sns.set(rc={'figure.figsize':(11.7,8.27)})

其他的选择可能是使用数字。rcParams的figsize设置图形大小如下:

from matplotlib import rcParams

# figure size in inches
rcParams['figure.figsize'] = 11.7,8.27

更多细节可以在matplotlib文档中找到

请注意,如果您试图传递给seaborn中的“图形级”方法(例如lmplot, catplot / factorplot, jointplot),您可以并且应该在参数中使用height和aspect指定此方法。

sns.catplot(data=df, x='xvar', y='yvar', 
    hue='hue_bar', height=8.27, aspect=11.7/8.27)

请参阅https://github.com/mwaskom/seaborn/issues/488和使用matplotlib面向对象接口使用seaborn进行绘图,以获得关于图形级方法不遵守轴规范的更多详细信息。

这也会起作用。

from matplotlib import pyplot as plt
import seaborn as sns    

plt.figure(figsize=(15,16))
sns.countplot(data=yourdata, ...)

除了elz回答关于返回多图网格对象的“图形级别”方法外,还可以使用以下方法显式设置图形的高度和宽度(即不使用纵横比):

import seaborn as sns 

g = sns.catplot(data=df, x='xvar', y='yvar', hue='hue_bar')
g.fig.set_figwidth(8.27)
g.fig.set_figheight(11.7)

Paul H和J. Li给出的最重要的答案并不适用于所有类型的海上人物。对于FacetGrid类型(例如ssn .lmplot()),使用size和aspect参数。

大小同时改变高度和宽度,保持纵横比。

Aspect只改变宽度,保持高度不变。

您总是可以通过使用这两个参数来获得您想要的大小。

来源:https://stackoverflow.com/a/28765059/3901029