python - Matplotlib 中的三角剖分与提供的 Traingles
问题描述
我有如下数据:x,y,三角形
在 MATLAB 上并使用 trisurf 函数,我提供 (triangles, x, y) 来获得结果,非常直接。
然而,在 Matplotlib 上,如果我使用相同的数据,我会得到:
三角形数量超出范围(如果我使用现有三角形)
如果我让 tri.triangulation de 决定三角形,我的几何之外的奇怪线(红线)。(德劳内三角剖分)。
也许我的问题需要不同的方法,如果有人可以指导我找到更好的解决方案,我会很高兴。
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]
[1]: https://drive.google.com/file/d/1HPlSu6HYzVpIgtT7y_maeNESUa5y1WW9/view?usp=sharing , https://drive.google.com/file/d/1YKFxfkU1iIkEfXPs9nZd6f-STkJNqT2Q/view?usp=sharing , https://drive.google.com/file/d/1njxGiYqucUv4YyhY6H0U35lfuN2_zPfw/view?usp=sharing
解决方案
解决了!最后发现这不是处理问题的正确方法。我不得不使用 patch.Polygon 来分别创建每个三角形。后来我根据函数输出(z)添加了一个颜色图。
非常高兴它起作用了!
推荐阅读
- wpf - 如何更新绑定到 UI 的集合?
- javascript - Django-如何通过 javascript 变量在模板中定义 django 变量?
- fpga - 使用 PCI EXPRESS 进行 FPGA 到 PC 的数据传输
- php - 将 Unicode 转换为 PHP 数组中的 HTML 实体
- cordova - Cordova 坚持将其添加到项目中
- java - Angular ng-cloak 与 Thymeleaf
- perl - 使用“严格引用”时不能将字符串用作数组引用
- java - 如何使用 Saxon XSLT 转换每个 xml 节点?
- python - python 日期时间到 np.datetime64
- c# - 从 Controller 调用 SignalR Core Hub 方法时的连接 ID