如何将多个类高斯2D线谱剖面堆叠为3D线框图?
实现多个2D剖面的3D线框图堆叠
没问题呀!当然可以把大量2D剖面整合到堆叠轴中,生成3D线框图。结合你现有的代码,我给你两种实用的实现方式,你可以按需选择:
方式1:循环绘制单条剖面线(灵活选剖面)
这种方式适合手动挑选部分剖面绘制,避免7万多条线过于密集重叠。代码修改如下:
import matplotlib.pyplot as plt # 假设你已经加载好data1b (shape: 71676, 64) 和 spatial (shape: 64) fig = plt.figure(figsize=(10, 8)) # 创建3D坐标轴 ax = fig.add_subplot(111, projection='3d') # 选每隔1000个剖面画一条,避免太挤(你可以按需调整step值) step = 1000 selected_profiles = range(0, data1b.shape[0], step) for profile_idx in selected_profiles: # x轴:空间坐标spatial;y轴:剖面的堆叠位置(用索引代替,也可以换成你的物理堆叠坐标) x = spatial y = [profile_idx] * len(x) # z轴:当前剖面的幅值数据 z_values = data1b[profile_idx] # 绘制单条3D线 ax.plot(x, y, z_values, linewidth=0.5) # 设置坐标轴标签,让图更清晰 ax.set_xlabel('Spatial Coordinate') ax.set_ylabel('Profile Index (Stacked Axis)') ax.set_zlabel('Amplitude') # 调整视角,方便观察 ax.view_init(elev=30, azim=45) plt.tight_layout() plt.show()
方式2:用plot_wireframe生成规整网格线图
如果想要更规整的线框网格效果,可以把数据整理成二维矩阵,直接用matplotlib的plot_wireframe:
import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(111, projection='3d') # 同样选部分剖面,避免数据量过大 step = 1000 selected_indices = np.arange(0, data1b.shape[0], step) # 提取选中的剖面数据 selected_data = data1b[selected_indices, :] # 生成网格坐标:X对应spatial,Y对应剖面的堆叠位置 X, Y = np.meshgrid(spatial, selected_indices) # 绘制线框图 ax.plot_wireframe(X, Y, selected_data, rstride=1, cstride=1, linewidth=0.5) # 设置标签和视角 ax.set_xlabel('Spatial Coordinate') ax.set_ylabel('Profile Index (Stacked Axis)') ax.set_zlabel('Amplitude') ax.view_init(elev=30, azim=45) plt.tight_layout() plt.show()
小提示:
- 如果你的剖面有对应的物理堆叠坐标(比如时间、深度等),直接把代码里的
profile_idx/selected_indices换成你的物理坐标数组就行,不用局限于索引。 - 要是觉得线条还是太密,就调大
step值,减少绘制的剖面数量;反之调小step可以展示更多细节。
内容的提问来源于stack exchange,提问作者eocahill
相关产品推荐
相关产品推荐

