使用Matplotlib a * y + b * x + c绘制3D表面

时间:2017-10-04 21:38:03

标签: python matplotlib

我是Matplotlib的新手,我需要在3d图中绘制一个平面。我在等式中有a,b和c的值,类似于1y + 2x + 3

theta = np.array([1,2,3])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(theta[0],theta[1],theta[2])
plt.show()

我知道这不是使用plot_surface()功能的正确方法,但我无法弄清楚如何使用。

更新1

我使用线框想出了一些东西。

# Plot the plane
X = np.linspace(0,100, 500)
Y = np.linspace(0,100, 500)
Z = np.dot(theta[0],X) + np.dot(theta[1],Y) + theta[2]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(X,Y,Z)
plt.show()

但它只显示一条线。

enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个:

0.025

您需要先创建变量的meshgrid,然后计算meshgrid上的函数值。

enter image description here

相关问题