如何更改Seaborn中regplot的绘图大小?

2024-04-19 06:49:54 发布

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

类似于matplotlib的fig.set_size_inches(18.5, 10.5)的东西。


Tags: sizematplotlibfigsetinches
2条回答

或者稍微短一点:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

# some artificial data
data = np.random.multivariate_normal([0,0], [[1,-0.5],[-0.5,1]], size=100)

# plot
sns.set_style('ticks')

g = sns.regplot(data[:,0], data[:,1])
g.figure.set_size_inches(18.5, 10.5)
sns.despine()

您可以首先通过plt.subplots()声明fig, ax对,然后在该图上设置适当的大小,并要求sns.regplot在该图上绘制ax

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

# some artificial data
data = np.random.multivariate_normal([0,0], [[1,-0.5],[-0.5,1]], size=100)

# plot
sns.set_style('ticks')
fig, ax = plt.subplots()
fig.set_size_inches(18.5, 10.5)
sns.regplot(data[:,0], data[:,1], ax=ax)
sns.despine()

enter image description here

相关问题 更多 >