如何更改海生地块的图形大小?

2024-04-16 20:08:17 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

您需要提前创建matplotlib图形和轴对象,指定图形的大小:

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)

您还可以通过在seabornset方法中将dictionary传递给具有键'figure.figsize'rc参数来设置图形大小:

import seaborn as sns

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

另一种选择是使用figure.figsizercParams设置图形大小,如下所示:

from matplotlib import rcParams

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

有关详细信息,请参见matplotlib documentation

您可以将上下文设置为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')

enter image description here

相关问题 更多 >