Hussain Niazi
Hussain Niazi

Reputation: 619

Python - matplotlib - how do I plot a plane from equation?

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

Upvotes: 10

Views: 12030

Answers (1)

Rory Daulton
Rory Daulton

Reputation: 22564

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:

enter image description here

That is not the greatest graph, but now you can modify some of the parameters to get just what you want.

Upvotes: 20

Related Questions