【发布时间】:2023-03-27 09:32:01
【问题描述】:
我有两个包含非结构化网格的 netcdf 文件。第一个网格每个面有 3 个顶点,第二个网格每个面有 4 个顶点。
对于每个面包含 3 个顶点的网格,我可以使用 matplotlib.tri 进行可视化(例如 triplot_demo.py:
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np
xy = np.asarray([
[-0.101, 0.872], [-0.080, 0.883], [-0.069, 0.888], [-0.054, 0.890],
[-0.045, 0.897], [-0.057, 0.895], [-0.073, 0.900], [-0.087, 0.898],
[-0.090, 0.904], [-0.069, 0.907], [-0.069, 0.921], [-0.080, 0.919],
[-0.073, 0.928], [-0.052, 0.930], [-0.048, 0.942], [-0.062, 0.949],
[-0.054, 0.958], [-0.069, 0.954], [-0.087, 0.952], [-0.087, 0.959],
[-0.080, 0.966], [-0.085, 0.973], [-0.087, 0.965], [-0.097, 0.965],
[-0.097, 0.975], [-0.092, 0.984], [-0.101, 0.980], [-0.108, 0.980],
[-0.104, 0.987], [-0.102, 0.993], [-0.115, 1.001], [-0.099, 0.996],
[-0.101, 1.007], [-0.090, 1.010], [-0.087, 1.021], [-0.069, 1.021],
[-0.052, 1.022], [-0.052, 1.017], [-0.069, 1.010], [-0.064, 1.005],
[-0.048, 1.005], [-0.031, 1.005], [-0.031, 0.996], [-0.040, 0.987],
[-0.045, 0.980], [-0.052, 0.975], [-0.040, 0.973], [-0.026, 0.968],
[-0.020, 0.954], [-0.006, 0.947], [ 0.003, 0.935], [ 0.006, 0.926],
[ 0.005, 0.921], [ 0.022, 0.923], [ 0.033, 0.912], [ 0.029, 0.905],
[ 0.017, 0.900], [ 0.012, 0.895], [ 0.027, 0.893], [ 0.019, 0.886],
[ 0.001, 0.883], [-0.012, 0.884], [-0.029, 0.883], [-0.038, 0.879],
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
[-0.077, 0.990], [-0.059, 0.993]])
x = np.degrees(xy[:, 0])
y = np.degrees(xy[:, 1])
triangles = np.asarray([
[65, 44, 20],
[65, 60, 44]])
triang = tri.Triangulation(x, y, triangles)
plt.figure()
plt.gca().set_aspect('equal')
plt.triplot(triang, 'go-', lw=1.0)
plt.title('triplot of user-specified triangulation')
plt.xlabel('Longitude (degrees)')
plt.ylabel('Latitude (degrees)')
plt.show()
-- 之后标注的相关点的索引
但是如何可视化每个面包含 4 个顶点(四边形)的非结构化网格?按照前面的例子,我的脸看起来像:
quatrang = np.asarray([
[65, 60, 44, 20]])
显然尝试tri.Triangulation 不起作用:
quatr = tri.Triangulation(x, y, quatrang)
ValueError: triangles must be a (?,3) array
我在 matplotlib 库中找不到关于每个面 4 个顶点的任何内容。非常感谢任何帮助..
编辑:根据一个最小、完整且可验证的示例更改了问题
【问题讨论】:
-
由于没有 Quatrangulation 或 simiar,因此在 matplotlib 中没有标准的方法来绘制它们。当然,您可以再次对网格进行三角剖分,以获得每个四边形 2 个三角形。或者,您可以绘制形状的 PolyCollection,给定它们在空间中的坐标。如需帮助,您需要提供一个可运行的示例 (minimal reproducible example)。
-
感谢@ImportanceOfBeingErnest 我已根据您的 cmets 修改了我的问题,以包含一个可运行的示例。
标签: matplotlib mesh triangulation quadrilaterals