I have an equation z=0.12861723162963065X + 0.0014024845304814665Y + 1.0964608113924048
I need to plot a 3D plane for this equation in python using matplotlib. I have already tried following this post -- Given general 3D plane equation, how can I plot this in python matplotlib?
However I am unable to set the x,y and z limits for this plane.
Can someone provide me the correct way of converting this equation into 3D plane. Thanks
Planes are represented by a Plane structure. Planes can be thought of as a zero-based, one-dimensional list containing four elements: the plane's origin (point3D), the plane's X axis direction (vector3d), the plane's Y axis direction (vector3d), and the plane's Z axis direction (vector3d).
We could plot 3D surfaces in Python too, the function to plot the 3D surfaces is plot_surface(X,Y,Z), where X and Y are the output arrays from meshgrid, and Z=f(X,Y) or Z(i,j)=f(X(i,j),Y(i,j)). The most common surface plotting functions are surf and contour. TRY IT!
You have it easy since your equation gives the value of z
for any values of x
and y
.
So choose any limits you like for x
and y
. You could even use the ones in the web page you linked to. Just calculate the z
values according to your equation. Here is code modified slightly from the linked page:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = np.linspace(-1,1,10)
y = np.linspace(-1,1,10)
X,Y = np.meshgrid(x,y)
Z=0.12861723162963065*X + 0.0014024845304814665*Y + 1.0964608113924048
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z)
And here is the result:
That is not the greatest graph, but now you can modify some of the parameters to get just what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With