【问题标题】:Given general 3D plane equation, how can I plot this in python matplotlib?给定一般的 3D 平面方程,我如何在 python matplotlib 中绘制它?
【发布时间】:2018-06-28 08:25:31
【问题描述】:

假设我有一个 3D 平面方程:

ax+by+cz=d

如何在 python matplotlib 中绘制?

我看到了一些使用 plot_surface 的示例,但它接受 x、y、z 值作为 2D 数组。我不明白如何将我的方程转换为plot_surface 的参数输入或matplotlib 中可用于此的任何其他函数。

【问题讨论】:

  • 您的问题到底是什么?一旦定义了 x 和 y(例如使用 meshgrid),z 就很容易计算...
  • 那是我不明白的部分,你能在答案中举个例子吗?假设我在 ax 和 by 中有值 a,b,我怎样才能将它放入 meshgrid?

标签: python matplotlib 3d


【解决方案1】:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

a,b,c,d = 1,2,3,4

x = np.linspace(-1,1,10)
y = np.linspace(-1,1,10)

X,Y = np.meshgrid(x,y)
Z = (d - a*X - b*Y) / c

fig = plt.figure()
ax = fig.gca(projection='3d')

surf = ax.plot_surface(X, Y, Z)

【讨论】:

  • 有争议的是,meshgrid 只是一个 Matlab 兼容包装器,而 numpy 的 mgrid 是“更原生的”mgrid
  • 如果 c = 0 会发生什么
  • @Julien 我使用您在此处提供的代码来可视化神经网络分类的决策边界平面,但它没有正确构建平面:stackoverflow.com/questions/61401114/…
  • @bambi 它不起作用,因为您错误地定义了平面方程。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-05
  • 2019-06-29
  • 2017-06-08
  • 1970-01-01
相关资源
最近更新 更多