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

How do I change the plot size of a regplot in Seaborn?

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

您可以先通过 plt.subplots() 声明 fig, ax 对,然后在该图形上设置适当的大小,然后让 sns.regplotax[=16= 上绘图]

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()

或者更短一点:

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()