如何从方程绘制平面

如何从方程绘制平面

本文介绍了Python - matplotlib - 如何从方程绘制平面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个等式z = 0.12861723162963065X + 0.0014024845304814665Y + 1.0964608113924048

我需要使用 matplotlib 在 python 中为这个方程绘制一个 3D 平面.我已经尝试过这篇文章-

那不是最好的图表,但现在您可以修改一些参数以获得您想要的.

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

解决方案

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.

这篇关于Python - matplotlib - 如何从方程绘制平面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 12:12