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

mean = [4, 2]
cov = [[1, 0], [0, 1]] # 协方差矩阵

x, y = np.random.multivariate_normal(mean, cov, 1000).T
data = {'x': x, 'y': y}
df = pd.DataFrame(data)

sns.kdeplot(data=df, x='x', y='y', cmap='Blues', shade=True, shade_lowest=False)
plt.show()

运行结果:

image-20211103204030549

从均值为42的二元标准正态分布中采样1000个点用seaborn画二维密度函数

原文地址: http://www.cveoy.top/t/topic/eM6Z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录