繁体   English   中英

是否有与 Z251D2BBFE9A3B95E5691CEBAZ30DC678 一起使用的 python 3d 地形 plot ?

[英]Is there a python 3d topographical plot that works with Pandas?

我正在处理 x、y 和 z 数据以获得具有高低的地板 map。 Z为位移传感器。 我需要 plot 一个带有渐变的地形 map。 我目前有一个 3D 散射 plot 和一个轮廓 plot 使用 ZF02113237A5A5F02113237A5A46640E34C9 这些效果很好,但线框 map 或局部 map 效果最好。 2D 或 3D 也可以工作。 先感谢您!

当前输出:

3D 散点

3D 轮廓

我正在努力实现的示例:

散景表面 3D plot

2D plot

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import holoviews as hv
from bokeh.models import ColumnDataSource
from mpl_toolkits.mplot3d import Axes3D
from holoviews import opts
hv.extension('bokeh', 'matplotlib')
%matplotlib widget
%matplotlib inline
%matplotlib nbagg
%matplotlib ipympl
plt.style.use('seaborn-white')


#Extend width of Jupyter Notebook
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

#Read CSV
df = pd.read_csv('Floor Scan.csv')
clean_df = df.dropna(axis = 0, how ='any')
print(clean_df)
print('')

z_offset = (clean_df['Displacement (in)'].min())
z_offset_abs = abs(z_offset)
print("Minimum Z:" + str(z_offset))

#3D SCATTER

fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111, projection='3d')

x = clean_df['fActualPosition_X (-)']
y = clean_df['fActualPosition_Y (-)']
z = clean_df['Displacement (in)']

ax.scatter(x, y, (z + z_offset_abs), c='b', marker='^')
plt.xlabel("fActualPosition_X (-)")
plt.ylabel("fActualPosition_Y (-)")

plt.show()
plt.savefig('Floor_Map_Scatter_3D.svg')

#3D CONTOUR

fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111, projection='3d')

X = clean_df['fActualPosition_X (-)'].astype(np.uint8)
Y = clean_df['fActualPosition_Y (-)'].astype(np.uint8)
Z = clean_df['Displacement (in)'].astype(np.uint8)

flatX = np.asarray(clean_df['fActualPosition_X (-)'])
flatY = np.asarray(clean_df['fActualPosition_Y (-)'])
flatZ = np.asarray(clean_df['Displacement (in)'])

# flatX, flatY = np.meshgrid(X, Y)
# flatZ = function(flatX, flatY, Z)

# print(flatX)
# print('')
# print(flatY)
# print('')
# print(flatZ)
# print('')

plt.tricontourf(flatX, flatY, (flatZ+z_offset_abs),20)
plt.show();
plt.savefig('Floor_Map_Contour_3D.svg')

听起来您的原始数据是孤立点的形式(来自像激光雷达这样的测距设备?),您想要的不仅仅是 plot 这些点,而是首先从这些点推断或插值一个表面,然后plot 那个表面。 两个所需的示例都采用已经计算的值网格和 plot 它们作为表面或图像,因此首先您需要制作这样的网格,这不是严格的绘图问题,而是数据处理之一。

创建网格的一种典型方法是将值聚合到笛卡尔坐标中,基本上只是计算每个网格单元的散点的平均值。 另一种是将所有点连接成一个三角形网格,该网格实际上可能形成也可能不形成表面(从 x,y -> z 映射的 function)。

您可以使用我们的库Datashader将几乎任何数据集聚合到常规网格中,然后可以使用 hvPlot ( https://hvplot.holoviz.org/user_guide/Gridded_Data.html ) 将其显示为图像或轮廓使用 HoloViews ( http://holoviews.org/reference/elements/plotly/Surface.html#elements-plotly-gallery-surface ) 的表面或线框。

如果你想要一个非结构化的网格,你可以使用 scipy.spatial 来计算三角剖分,然后 HoloViews 来可视化它( http://holoviews.org/reference/elements/bokeh/TriMesh.html#elements-bokeh-gallery-trime ) .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM