python - 从 excel xlsx 到 3d 绘图的 3D 绘图测量数据
问题描述
我正在尝试将 XYZ 值转换为网格或使用函数直接绘制它们。
我有一张带有测量值的表格。在不同压力下测量组分的流量。所以有以下测量值:
压力 1:X 轴:位置值 Y 轴:流量值
压力 2:X 轴:位置值 Y 轴:流量值
……
使用 8 种不同的压力,我总共有 16 列带有 XY 值。
实际上,我不认为这有那么困难。如果将 Z 轴(深度)切成 8 个切片,则每个切片都有 XY 坐标。因此,软件只需将它们线性连接或与绘图中的样条连接。
是否有一个函数可以为每个 Z 值分配一个 XY 列,并且可以将其输出为曲面图?
为了更清楚,我创建了一个带有值的小示例虚拟表:
解决方案
这是你想要的吗?
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()
。
推荐阅读
- ionic4 - 滚动位置恢复设置在 ionic 4 angular 8 中不起作用
- r - 如何选择随机向量
- apache-spark - 在 Pyspark 中使用 contains 和 udf 时出现问题:AttributeError: 'NoneType' object has no attribute 'lower'
- android - 如何通过按返回返回到上一个片段?
- python - 如何使用python使用mssql+pyodbc连接字符串创建和删除数据库
- javascript - 获取 jquery each() 中多个输入字段的总和
- php - 将 PHP 5.6.16 升级到 7.2.9 后,SoapClient::__doRequest() 不工作总是返回空响应
- django - Django注释字段未传递给序列化程序
- sql - 有没有办法检查两个数据集是否相同(Pentaho 和 OracleDB)
- java - HtmlUnit - 按值获取电台