[得到ValueError:'顶点'必须是形状为Nx2的2D列表或数组,当它为Nx2时?

问题描述 投票:0回答:1

我正在尝试使用此处概述的节点坐标和连通性绘制网格:

link

我有一个存储在numpy数组中的节点坐标列表(x y和z坐标)

我将x和y定义为:

x = coords[:,0]
y = coords[:,1]

我在一个numpy数组connectivity中具有节点连接性,它具有连接在一起的坐标的ID号

然后,按照他们的示例,执行以下操作:

xy = np.c_[x,y]
verts= xy[connectivity]
pc = matplotlib.collections.PolyCollection(verts)

我收到此错误:

  File "C:\Users\deden\AppData\Local\Continuum\anaconda3\envs\dhi\lib\site-packages\matplotlib\path.py", line 130, in __init__
    "'vertices' must be a 2D list or array with shape Nx2")

ValueError: 'vertices' must be a 2D list or array with shape Nx2

检查:

xy.shape[1]为2且xy.ndim是2

回溯中文件的第130行是:

vertices = _to_unmasked_float_array(vertices)
if vertices.ndim != 2 or vertices.shape[1] != 2:
    raise ValueError(
        "'vertices' must be a 2D list or array with shape Nx2")

_to_unmasked_float_array(vertices)电话:

def _to_unmasked_float_array(x):
    """
    Convert a sequence to a float array; if input was a masked array, masked
    values are converted to nans.
    """
    if hasattr(x, 'mask'):
        return np.ma.asarray(x, float).filled(np.nan)
    else:
        return np.asarray(x, float)

如果verts.shape[1]verts.ndim = 2,我不明白为什么会收到此错误消息,>

也是np.asarray(verts, float).shape[1]np.asarray(verts, float).ndim也是2

到底发生了什么?我错过了什么吗?非常感谢任何人的帮助

也..

verts.shape

返回

(181660, 2)

我正在尝试使用此处概述的节点坐标和连通性绘制网格:链接我有一个存储在numpy数组中的节点坐标列表(xy和z坐标),我将x和y定义为:x = ...] >

python matplotlib mesh
1个回答
0
投票

由于要绘制集合,所以希望verts是顶点的列表[[每个多边形

。从技术上讲,如the documentation puts it
© www.soinside.com 2019 - 2024. All rights reserved.