Matplotlib中的三角剖分,带有提供的Traingle

2024-06-28 10:50:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有如下数据:x,y,三角形

在MATLAB上,使用trisurf函数,我提供(三角形,x,y)来得到结果,非常直接

但是,在Matplotlib上,如果使用相同的数据:

  • 三角形数超出边界(如果使用现有三角形)

  • 如果我让tri.triangulation去决定三角形,几何体外的奇怪线(红线)。(Delaunay三角剖分)

也许我的问题需要不同的方法,如果有人能指导我找到更好的解决方案,我会很高兴

import matplotlib.pyplot as plt
import matplotlib.tri as tri
import pandas as pd
import numpy as np

dlel = pd.read_fwf('HSH_Calculation.LEL')
dlnd = pd.read_fwf('HSH_Calculation.LND')
dt = pd.read_fwf('HSH_Calculation.HTD')

xy = np.asarray(dlnd.iloc[:, 3:5])

x = xy[:, 0]
y = xy[:, 1]
triangles = np.asarray(dlel.iloc[:, 1:4])
# triang = tri.triangulation(x,y)
triang = tri.Triangulation(x, y)


plt.figure()
plt.gca().set_aspect('equal')
# plt.triplot(x, y, triangles, 'go-', lw=1.0)
plt.triplot(triang, 'go-', lw=1.0)
plt.title('triplot of user-specified triangulation')
plt.xlabel('Longitude (degrees)')
plt.ylabel('Latitude (degrees)')

plt.show()

[计算档案][1]

output

[1]:https://drive.google.com/file/d/1HPlSu6HYzVpIgtT7y_maeNESUa5y1WW9/view?usp=sharinghttps://drive.google.com/file/d/1YKFxfkU1iIkEfXPs9nZd6f-STkJNqT2Q/view?usp=sharinghttps://drive.google.com/file/d/1njxGiYqucUv4YyhY6H0U35lfuN2_zPfw/view?usp=sharing


Tags: importreadasnpplttripdxy
1条回答
网友
1楼 · 发布于 2024-06-28 10:50:17

解决了! 最后发现这不是解决问题的正确方法。 我不得不使用patches.Polygon来分别创建每个三角形。 我后来根据函数输出(z)添加了一个颜色贴图

非常高兴它成功了

相关问题 更多 >