Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given general 3D plane equation, how can I plot this in python matplotlib?

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

ax+by+cz=d

How can I plot this in python 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.

like image 373
Algorithman Avatar asked Jan 19 '18 06:01

Algorithman


People also ask

Can matplotlib Pyplot be used to display 3d plots?

Matplotlib was introduced keeping in mind, only two-dimensional plotting. But at the time when the release of 1.0 occurred, the 3d utilities were developed upon the 2d and thus, we have 3d implementation of data available today! The 3d plots are enabled by importing the mplot3d toolkit.

How do I plot a line in matplotlib 3d?

MatPlotLib with PythonCreate a new figure or activate an existing figure using figure() method. Add an axes as a subplot arrangement with 3D projection. Plot x, y and z data points using plot() method. To display the figure, use show() method.


1 Answers

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)
like image 130
Julien Avatar answered Oct 31 '22 13:10

Julien