首页 > 解决方案 > 从 excel xlsx 到 3d 绘图的 3D 绘图测量数据

问题描述

我正在尝试将 XYZ 值转换为网格或使用函数直接绘制它们。

我有一张带有测量值的表格。在不同压力下测量组分的流量。所以有以下测量值:

使用 8 种不同的压力,我总共有 16 列带有 XY 值。

实际上,我不认为这有那么困难。如果将 Z 轴(深度)切成 8 个切片,则每个切片都有 XY 坐标。因此,软件只需将它们线性连接或与绘图中的样条连接。

是否有一个函数可以为每个 Z 值分配一个 XY 列,并且可以将其输出为曲面图?

为了更清楚,我创建了一个带有值的小示例虚拟表:

XYZ 值

标签: pythonexcelmatplotlibplotlyxyz

解决方案


这是你想要的吗?

import matplotlib.pyplot as plt 
import numpy as np 
 
# generate x, y 
x = np.linspace(0, 10, 51) 
w = np.linspace(0.5, 0.20, 10) 
y = np.array([np.sin(wi*x)/wi for wi in w]) # 10 rows, 51 cols
# and a very generic z 
z = np.linspace(1, 10, 10) 
 
# note that in a surface plot the indipendent variable is Z, 
# so IF our indipendent variable is y… 
X, Y = np.meshgrid(x, z) ; Z = y # X, Y have 10 rows, 51 cols too
 
# this stuff is pretty standard, you can find info everywhere
fig = plt.figure() ; ax = fig.gca(projection='3d') 
surf = ax.plot_surface(X, Y, Z, cmap='viridis') 
ax.set(xlabel='x', ylabel='z', zlabel='y') 
ax.view_init(elev=15, azim=-100) 
fig.colorbar(surf, shrink=0.67) # the 1st arg is the output of plot_surface

在此处输入图像描述

颜色图是默认的,您可以按名称选择不同的。您可以使用 . 查看完整的颜色图名称列表plt.colormaps()


推荐阅读