印刷に適した画像サイズに変更するにはどうすればよいですか?
例えば、A4サイズの用紙(11.7インチ×8.27インチ)を横向きで使用したい場合。
また、seaborn の set
メソッドで rc
パラメータに 'figure.figsize'
をキーに辞書を渡すことで、図のサイズを設定できます:
import seaborn as sns
sns.set(rc={'figure.figsize':(11.7,8.27)})
また、rcParams
のfigure.figsize
を使用して、以下のように図の大きさを設定することも可能です:
from matplotlib import rcParams
# figure size in inches
rcParams['figure.figsize'] = 11.7,8.27
詳細はmatplotlibのドキュメントに記載されています。
先にmatplotlibのFigureとAxesオブジェクトを作成し、図の大きさを指定する必要があります:
from matplotlib import pyplot
import seaborn
import mylib
a4_dims = (11.7, 8.27)
df = mylib.load_data()
fig, ax = pyplot.subplots(figsize=a4_dims)
seaborn.violinplot(ax=ax, data=df, **violin_options)
コンテキストを poster
に設定するか、手動で fig_size
を設定することができます。
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
np.random.seed(0)
n, p = 40, 8
d = np.random.normal(0, 2, (n, p))
d += np.log(np.arange(1, p + 1)) * -5 + 10
# plot
sns.set_style('ticks')
fig, ax = plt.subplots()
# the size of A4 paper
fig.set_size_inches(11.7, 8.27)
sns.violinplot(data=d, inner="points", ax=ax)
sns.despine()
fig.savefig('example.png')
海岸で「図のレベル」メソッド(たとえば、「lmplot」、「catplot」、「factorplot」、「jointplot」)に渡そうとしている場合は、「height」を使用して引数内でこれを指定できます。 アスペクト
。
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およびhttps://stackoverflow.com/questions/23969619/plotting-with-seaborn-using-the-matplotlib-object-oriented-interfaceを参照してください。図レベルの方法は軸の仕様に従わないという事実の詳細。
マルチプロットグリッドオブジェクトを返す「図レベル」メソッドに関する 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
タイプ(たとえば sns.lmplot()
)の場合、 size
および aspect
パラメータを使用します。
「サイズ」はアスペクト比を維持しながら、高さと幅の両方を変更します。
「アスペクト」は幅を変更するだけで、高さは一定に保たれます。
これらの2つのパラメーターでプレイすることで、いつでも希望のサイズを取得できます。