from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
z = np.array([[x**2 + y**2 for x in range(20)] for y in range(20)])
x, y = np.meshgrid(range(z.shape[0]), range(z.shape[1]))
# show hight map in 3d
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z)
plt.title('z as 3d height map')
plt.show()
# show hight map in 2d
plt.figure()
plt.title('z as 2d heat map')
p = plt.imshow(z)
plt.colorbar(p)
plt.show()
2条答案
按热度按时间lo8azlld1#
下面是matplotlib的代码
在此,z:
这里是z的2D图:
sqserrrh2#
即使我同意其他人的观点,meshgrids并不难,但我仍然认为
Mayavi
包提供了一个解决方案(检查函数surf)from mayavi import mlab mlab.surf(Z) mlab.show()