鉴于一般的 3D 平面方程,我如何在 python matplotlib 中绘制它?

问题描述:

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

Let's say I have a 3D plane equation:

ax+by+cz=d

如何在 python matplotlib 中绘制此图?

How can I plot this in python matplotlib?

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

I saw some examples using plot_surface, but it accepts x,y,z values as 2D array. I don't understand how can I convert my equation into the parameter inputs to plot_surface or any other functions in matplotlib that can be used for this.

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)