Python:用随机x和y绘制3d函数的最佳方法

2024-06-16 14:18:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我生成了一个二维数组,在每一行中,有一个随机x,随机y和f(x,y)。 我选择了randomx和{},因为f(x, y)的计算时间很长。在

我使用Axes3D中的Axes3D来绘制结果:

ax.scatter(tableau[:,0], tableau[:,1], zs=tableau[:,2], c='r', marker='o')

结果没有用。不可能理解f的形状

draw of f with random x and y

有没有更好的方法来画f(x,y)?在


Tags: 方法时间绘制数组axmarker形状zs
2条回答

enter image description here

  fig = plt.figure()
  ax = fig.add_subplot(111, projection='3d')
  elev=70 
  azim=30
  X, Y, Z = tableau[:,0], tableau[:,1], tableau[:,2]
  ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5)

  ax.view_init(elev, azim)

  plt.draw()

如果您的目标是更好地查看函数的形状,可以使用matplotlib方法view_init(elev=None, azim=None)旋转轴;它设置轴角度的仰角和方位角。例如:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Test 3D function
X, Y, Z = axes3d.get_test_data(0.1)
ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5)

ax.view_init(elev, azim)

plt.draw()

当标高=30,方位角=45时:

enter image description here

当标高=30,方位角=90时:

enter image description here

当标高=0,方位角=90时:

enter image description here

相关问题 更多 >