![](/img/trans.png)
[英]Visualizing a multivariate normal distribution with numpy and matplotlib in 3 Dimensions
[英]Visualizing a multivariate normal distribution in 3D with python
这个 plot 几乎肯定是使用matplotlib
生产的。 看看他们的教程。 Stack Overflow 还有一个matplotlib
标签。
对于 3D 中的 plot,您需要使用mplot3d
工具包。
试试这个脚本
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
def gauss1(x):
return np.exp(-(x**2))
def gauss(x, y):
return gauss1(x)*gauss1(2*y)
fig = plt.figure()
ax = fig.gca(projection='3d')
x = np.linspace(-3, 3, 100)
y = np.linspace(-3, 3, 100)
X, Y = np.meshgrid(x, y)
Z = gauss(X, Y)
ax.plot_surface(X, Y, Z, rstride=2, cstride=2, alpha=0.4, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-4, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='y', offset=4, cmap=cm.coolwarm)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
这会产生以下结果
我不知道如何 plot 只有轮廓线的投影,但至少是一些东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.