我想绘制这样的函数:f(x,z)= x / z其中x = z = list(range(, 10)
具有x和z的所有组合。我尝试过:
def f(X, Y):
return X/Y
def data(r=10):
X = [i/10 for i in range(0, r)]
Y = X.copy()
x, y = zip(*[[e, i] for e in Y for i in X])
z = [f(x[i], y[i]) if y[i] else float('Nan') for i in range(len(x))]
return x, y, z
所以我得到x,y和z数据。我现在可以使用这3个列表来绘制3D图吗?我只发现使用numpy-arrays解决方案...
感谢您的帮助!
您可以将trisurf
与一维列表一起使用
trisurf
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# Your functions here
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, z)
plt.show()