2024-05-18 12:33:44 发布
网友
尽管关于如何用XYZ格式打印三维曲面,有很多资料来源。我有一个来自扫描激光的CSV文件,它没有提供关于X和Y的坐标信息,只有矩形网格的Z坐标。在
文件是800 x 1600,只有z坐标。Excel可以很容易地用曲面图来绘制它,但受大小的限制。在
我如何解决这个问题?在
Screenshot of data format
您只需要创建X和Y坐标的数组。我们可以用^{}来做这个。在下面的示例中,我将cell size设置为1,但是您可以通过更改cellsize变量轻松地缩放该值。在
X
Y
cellsize
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np # Create x, y coords nx, ny = 800, 1600 cellsize = 1. x = np.arange(0., float(nx), 1.) * cellsize y = np.arange(0., float(ny), 1.) * cellsize X, Y = np.meshgrid(x, y) # dummy data Z = (X**2 + Y**2) / 1e6 # Create matplotlib Figure and Axes fig = plt.figure() ax = fig.add_subplot(111, projection='3d') print X.shape, Y.shape, Z.shape # Plot the surface ax.plot_surface(X, Y, Z) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.show()
您只需要创建} 来做这个。在下面的示例中,我将cell size设置为1,但是您可以通过更改
X
和Y
坐标的数组。我们可以用^{cellsize
变量轻松地缩放该值。在相关问题 更多 >
编程相关推荐