如何使用python绘制平行于x轴和z轴的平面?

时间:2019-10-14 06:14:25

标签: python matplotlib

我正在尝试绘制一个平行于x轴和z轴(xz平面)的平面。

code

composer.json

是要绘制相似的平面。

要使该平面平行于xz平面,import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D point = np.array([1, 2, 3]) normal = np.array([1, 1, 2]) # a plane is a*x+b*y+c*z+d=0 # [a,b,c] is the normal. Thus, we have to calculate # d and we're set d = -point.dot(normal) # create x,y xx, yy = np.meshgrid(range(10), range(10)) # calculate corresponding z z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2] # plot the surface plt3d = plt.figure().gca(projection='3d') plt3d.plot_surface(xx, yy, z) plt.show() 中的参数a和c必须为0。

当我设置a*x+b*y+c*z+d=0时,飞机消失了。

该如何解决?

1 个答案:

答案 0 :(得分:0)

在您的代码中,计算0时将除以z。 您可以尝试以下方法:

plt3d = plt.figure().gca(projection='3d')
xx, zz = np.meshgrid(range(10), range(10))
yy = 2 
plt3d.plot_surface(xx, yy, zz)
plt.show()