用python绘制三维曲面

2024-05-18 12:33:44 发布

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

尽管关于如何用XYZ格式打印三维曲面,有很多资料来源。我有一个来自扫描激光的CSV文件,它没有提供关于X和Y的坐标信息,只有矩形网格的Z坐标。在

文件是800 x 1600,只有z坐标。Excel可以很容易地用曲面图来绘制它,但受大小的限制。在

我如何解决这个问题?在

Screenshot of data format


Tags: 文件ofcsv信息格式来源绘制excel
1条回答
网友
1楼 · 发布于 2024-05-18 12:33:44

您只需要创建XY坐标的数组。我们可以用^{}来做这个。在下面的示例中,我将cell size设置为1,但是您可以通过更改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()

enter image description here

相关问题 更多 >

    热门问题