【发布时间】:2022-01-25 22:44:48
【问题描述】:
我正在尝试创建一个适合高斯分布的数据集。 x 和 y 值将相同,并且在 z 轴上,这些值将符合高斯分布。将此站点作为自己的资源:@987654321@ 我编写了以下代码。但不幸的是,我得到的输出与我给出的链接中的不同。我认为数学公式有误。如果你能帮我修复它,我会很高兴。 While I was waiting for a graph like thisI got that kind of graph.
提前谢谢你。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
def np_bivariate_normal_pdf(domain, mean, variance):
X = np.arange(-domain+mean, domain+mean, variance)
Y = np.arange(-domain+mean, domain+mean, variance)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = ((1. / np.sqrt(2 * np.pi)) * np.exp(-.5*R**2))
return X, Y, Z
def plt_plot_bivariate_normal_pdf(x, y, z):
fig = plt.figure(figsize=(10, 10))
ax = fig.gca(projection='3d')
ax.plot_surface(x, y, z,
cmap=cm.coolwarm,
linewidth=0,
antialiased=True)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z');
ax.set_xlim(-5, +20)
ax.set_ylim(-5, +20)
plt.show()
a = np_bivariate_normal_pdf(0.75, 5, 0.01)
b = np_bivariate_normal_pdf(1.875, 3, 0.025)
c = np_bivariate_normal_pdf(1.5, 7.5, 0.02)
d = np_bivariate_normal_pdf(2.25, 12, 0.03)
plt_plot_bivariate_normal_pdf(*a)
plt_plot_bivariate_normal_pdf(*b)
plt_plot_bivariate_normal_pdf(*c)
plt_plot_bivariate_normal_pdf(*d)
【问题讨论】:
标签: python numpy matplotlib dataset gaussian