简体   繁体   中英

how to create a 3D height map in python

I have a 2D array Z that stores the height at that element's position. Other than using the method here in which I need to create array X and Y with the same size as Z, are there any simpler methods to create a 3D height map?

The 3D surface height map is something like the first surface plot here .

即使我同意其他网格并不困难,我仍然认为Mayavi包提供了一个解决方案(检查功能冲浪

from mayavi import mlab mlab.surf(Z) mlab.show()

Here the code for matplotlib

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()

here the 3D plot of z: 在此输入图像描述

and here the 2D plot of z: 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM