从excel xlsx到3d图的3D图测量数据

问题描述

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

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

  • 压力1: X轴:位置值 Y轴:流量值

  • 压力2: X轴:位置值 Y轴:流量值

  • ....

在8种不同的压力下,我总共有16列具有X-Y值的列。

实际上,我不认为这有那么困难。如果将Z轴(深度)切成8个切片,则每个切片都有X-Y坐标。因此,该软件只需要将它们线性连接或与样条线相连即可。

是否有为每个Z值分配一个X-Y列的函数,并且可以将其输出为表面图?

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

XYZ Values

解决方法

这是您想要的吗?

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

enter image description here

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

,

这不是完全的答案,因为我想从Excel表中导入DataFrame。 在Excel表中,输入的值与上一封邮件中的图片相同。我想用3D绘制它们。

我按如下所示导入了数据

from mpl_toolkits.mplot3d import Axes3D
import pandas as pd


fig = plt.figure()
ax = Axes3D(fig)

df=pd.read_excel('raw.xlsx')

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...