【问题标题】:How to plot a plane that is parallel to both of x-axis and z-axis with python?如何用python绘制一个平行于x轴和z轴的平面?
【发布时间】:2019-10-14 15:07:28
【问题描述】:

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

这个code

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()

是绘制一个相似的平面。

要使平面平行于 xz 平面,a*x+b*y+c*z+d=0 中的参数 a 和 c 需要为 0。

当我设置normal = np.array([0, 2, 0]) 时,飞机消失了。

如何解决?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    在您的代码中,计算 z 时除以 0。 你可以试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-24
      • 2021-09-11
      • 2023-01-30
      • 1970-01-01
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      相关资源
      最近更新 更多