当前位置: 首页>>代码示例>>Python>>正文


Python tri.Triangulation方法代码示例

本文整理汇总了Python中matplotlib.tri.Triangulation方法的典型用法代码示例。如果您正苦于以下问题:Python tri.Triangulation方法的具体用法?Python tri.Triangulation怎么用?Python tri.Triangulation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.tri的用法示例。


在下文中一共展示了tri.Triangulation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_tripcolor

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def test_tripcolor():
    x = np.asarray([0, 0.5, 1, 0,   0.5, 1,   0, 0.5, 1, 0.75])
    y = np.asarray([0, 0,   0, 0.5, 0.5, 0.5, 1, 1,   1, 0.75])
    triangles = np.asarray([
        [0, 1, 3], [1, 4, 3],
        [1, 2, 4], [2, 5, 4],
        [3, 4, 6], [4, 7, 6],
        [4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])

    # Triangulation with same number of points and triangles.
    triang = mtri.Triangulation(x, y, triangles)

    Cpoints = x + 0.5*y

    xmid = x[triang.triangles].mean(axis=1)
    ymid = y[triang.triangles].mean(axis=1)
    Cfaces = 0.5*xmid + ymid

    plt.subplot(121)
    plt.tripcolor(triang, Cpoints, edgecolors='k')
    plt.title('point colors')

    plt.subplot(122)
    plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
    plt.title('facecolors') 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:27,代码来源:test_triangulation.py

示例2: test_delaunay_duplicate_points

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def test_delaunay_duplicate_points():
    # x[duplicate] == x[duplicate_of]
    # y[duplicate] == y[duplicate_of]
    npoints = 10
    duplicate = 7
    duplicate_of = 3

    np.random.seed(23)
    x = np.random.random((npoints))
    y = np.random.random((npoints))
    x[duplicate] = x[duplicate_of]
    y[duplicate] = y[duplicate_of]

    # Create delaunay triangulation.
    triang = mtri.Triangulation(x, y)

    # Duplicate points should be ignored, so the index of the duplicate points
    # should not appear in any triangle.
    assert_array_equal(np.unique(triang.triangles),
                       np.delete(np.arange(npoints), duplicate)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:22,代码来源:test_triangulation.py

示例3: test_triinterpcubic_geom_weights

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def test_triinterpcubic_geom_weights():
    # Tests to check computation of weights for _DOF_estimator_geom:
    # The weight sum per triangle can be 1. (in case all angles < 90 degrees)
    # or (2*w_i) where w_i = 1-alpha_i/np.pi is the weight of apex i ; alpha_i
    # is the apex angle > 90 degrees.
    (ax, ay) = (0., 1.687)
    x = np.array([ax, 0.5*ax, 0., 1.])
    y = np.array([ay, -ay, 0., 0.])
    z = np.zeros(4, dtype=np.float64)
    triangles = [[0, 2, 3], [1, 3, 2]]
    sum_w = np.zeros([4, 2])  # 4 possibilities ; 2 triangles
    for theta in np.linspace(0., 2*np.pi, 14):  # rotating the figure...
        x_rot = np.cos(theta)*x + np.sin(theta)*y
        y_rot = -np.sin(theta)*x + np.cos(theta)*y
        triang = mtri.Triangulation(x_rot, y_rot, triangles)
        cubic_geom = mtri.CubicTriInterpolator(triang, z, kind='geom')
        dof_estimator = mtri.triinterpolate._DOF_estimator_geom(cubic_geom)
        weights = dof_estimator.compute_geom_weights()
        # Testing for the 4 possibilities...
        sum_w[0, :] = np.sum(weights, 1) - 1
        for itri in range(3):
            sum_w[itri+1, :] = np.sum(weights, 1) - 2*weights[:, itri]
        assert_array_almost_equal(np.min(np.abs(sum_w), axis=0),
                                  np.array([0., 0.], dtype=np.float64)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:26,代码来源:test_triangulation.py

示例4: _get_tri

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def _get_tri(self):
        import matplotlib.tri as tri
        
        _x,_y = [],[]
        # ~ df = 1
        for n in self.get_nodes():
            _x.append(n.x)
            # ~ _x.append(n.x + n.ux*df)
            _y.append(n.y)
            # ~ _y.append(n.y + n.uy*df)
            
        tg = []
        for e in self.get_elements():
            ni,nj,nm = e.get_nodes()
            tg.append([ni.label, nj.label, nm.label])
            
        tr = tri.Triangulation(_x,_y, triangles=tg)
        return tr 
开发者ID:JorgeDeLosSantos,项目名称:nusa,代码行数:20,代码来源:model.py

示例5: test_triinterpcubic_geom_weights

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def test_triinterpcubic_geom_weights():
    # Tests to check computation of weights for _DOF_estimator_geom:
    # The weight sum per triangle can be 1. (in case all angles < 90 degrees)
    # or (2*w_i) where w_i = 1-alpha_i/np.pi is the weight of apex i; alpha_i
    # is the apex angle > 90 degrees.
    (ax, ay) = (0., 1.687)
    x = np.array([ax, 0.5*ax, 0., 1.])
    y = np.array([ay, -ay, 0., 0.])
    z = np.zeros(4, dtype=np.float64)
    triangles = [[0, 2, 3], [1, 3, 2]]
    sum_w = np.zeros([4, 2])  # 4 possibilities; 2 triangles
    for theta in np.linspace(0., 2*np.pi, 14):  # rotating the figure...
        x_rot = np.cos(theta)*x + np.sin(theta)*y
        y_rot = -np.sin(theta)*x + np.cos(theta)*y
        triang = mtri.Triangulation(x_rot, y_rot, triangles)
        cubic_geom = mtri.CubicTriInterpolator(triang, z, kind='geom')
        dof_estimator = mtri.triinterpolate._DOF_estimator_geom(cubic_geom)
        weights = dof_estimator.compute_geom_weights()
        # Testing for the 4 possibilities...
        sum_w[0, :] = np.sum(weights, 1) - 1
        for itri in range(3):
            sum_w[itri+1, :] = np.sum(weights, 1) - 2*weights[:, itri]
        assert_array_almost_equal(np.min(np.abs(sum_w), axis=0),
                                  np.array([0., 0.], dtype=np.float64)) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:26,代码来源:test_triangulation.py

示例6: test_trirefiner_fortran_contiguous_triangles

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def test_trirefiner_fortran_contiguous_triangles():
    # github issue 4180.  Test requires two arrays of triangles that are
    # identical except that one is C-contiguous and one is fortran-contiguous.
    triangles1 = np.array([[2, 0, 3], [2, 1, 0]])
    assert not np.isfortran(triangles1)

    triangles2 = np.array(triangles1, copy=True, order='F')
    assert np.isfortran(triangles2)

    x = np.array([0.39, 0.59, 0.43, 0.32])
    y = np.array([33.99, 34.01, 34.19, 34.18])
    triang1 = mtri.Triangulation(x, y, triangles1)
    triang2 = mtri.Triangulation(x, y, triangles2)

    refiner1 = mtri.UniformTriRefiner(triang1)
    refiner2 = mtri.UniformTriRefiner(triang2)

    fine_triang1 = refiner1.refine_triangulation(subdiv=1)
    fine_triang2 = refiner2.refine_triangulation(subdiv=1)

    assert_array_equal(fine_triang1.triangles, fine_triang2.triangles) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:23,代码来源:test_triangulation.py

示例7: test_qhull_triangle_orientation

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def test_qhull_triangle_orientation():
    # github issue 4437.
    xi = np.linspace(-2, 2, 100)
    x, y = map(np.ravel, np.meshgrid(xi, xi))
    w = np.logical_and(x > y - 1, np.logical_and(x < -1.95, y > -1.2))
    x, y = x[w], y[w]
    theta = np.radians(25)
    x1 = x*np.cos(theta) - y*np.sin(theta)
    y1 = x*np.sin(theta) + y*np.cos(theta)

    # Calculate Delaunay triangulation using Qhull.
    triang = mtri.Triangulation(x1, y1)

    # Neighbors returned by Qhull.
    qhull_neighbors = triang.neighbors

    # Obtain neighbors using own C++ calculation.
    triang._neighbors = None
    own_neighbors = triang.neighbors

    assert_array_equal(qhull_neighbors, own_neighbors) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:23,代码来源:test_triangulation.py

示例8: triangulate_bary

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def triangulate_bary(bary):
    """
    Triangulate a single barycentric triangle using matplotlib.

    Argument
    --------
    bary: barycentric matrix obtained using get_barymat.

    Return
    ------
    dely.edges: array (nedges, 2) that contains the indices of the two vertices
                 that form each edge after the triangulation.
    dely.triangles:array (ntriangles, 3) that contains the indices of the three
                   vertices that form each triangle after the triangulation. 
    """

    x = numpy.cos(-numpy.pi/4.)*bary[:, 0] + numpy.sin(-numpy.pi/4.)*bary[:, 1]
    y = bary[:, 2]

    dely = Triang.Triangulation(x, y)
    return dely.edges, dely.triangles 
开发者ID:pygbe,项目名称:pygbe,代码行数:23,代码来源:mesh_ellipsoid.py

示例9: __init__

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def __init__(self, triangulation):
        if not isinstance(triangulation, Triangulation):
            raise ValueError("Expected a Triangulation object")
        self._triangulation = triangulation 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:tritools.py

示例10: __init__

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def __init__(self, triangulation, z, trifinder=None):
        if not isinstance(triangulation, Triangulation):
            raise ValueError("Expected a Triangulation object")
        self._triangulation = triangulation

        self._z = np.asarray(z)
        if self._z.shape != self._triangulation.x.shape:
            raise ValueError("z array must have same length as triangulation x"
                             " and y arrays")

        if trifinder is not None and not isinstance(trifinder, TriFinder):
            raise ValueError("Expected a TriFinder object")
        self._trifinder = trifinder or self._triangulation.get_trifinder()

        # Default scaling factors : 1.0 (= no scaling)
        # Scaling may be used for interpolations for which the order of
        # magnitude of x, y has an impact on the interpolant definition.
        # Please refer to :meth:`_interpolate_multikeys` for details.
        self._unit_x = 1.0
        self._unit_y = 1.0

        # Default triangle renumbering: None (= no renumbering)
        # Renumbering may be used to avoid unecessary computations
        # if complex calculations are done inside the Interpolator.
        # Please refer to :meth:`_interpolate_multikeys` for details.
        self._tri_renum = None

    # __call__ and gradient docstrings are shared by all subclasses
    # (except, if needed, relevant additions).
    # However these methods are only implemented in subclasses to avoid
    # confusion in the documentation. 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:33,代码来源:triinterpolate.py

示例11: __init__

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def __init__(self, triangulation):
        if not isinstance(triangulation, Triangulation):
            raise ValueError('Expected a Triangulation object')
        self._triangulation = triangulation 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:trifinder.py

示例12: __init__

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def __init__(self, triangulation, z, trifinder=None):
        if not isinstance(triangulation, Triangulation):
            raise ValueError("Expected a Triangulation object")
        self._triangulation = triangulation

        self._z = np.asarray(z)
        if self._z.shape != self._triangulation.x.shape:
            raise ValueError("z array must have same length as triangulation x"
                             " and y arrays")

        if trifinder is not None and not isinstance(trifinder, TriFinder):
            raise ValueError("Expected a TriFinder object")
        self._trifinder = trifinder or self._triangulation.get_trifinder()

        # Default scaling factors : 1.0 (= no scaling)
        # Scaling may be used for interpolations for which the order of
        # magnitude of x, y has an impact on the interpolant definition.
        # Please refer to :meth:`_interpolate_multikeys` for details.
        self._unit_x = 1.0
        self._unit_y = 1.0

        # Default triangle renumbering: None (= no renumbering)
        # Renumbering may be used to avoid unnecessary computations
        # if complex calculations are done inside the Interpolator.
        # Please refer to :meth:`_interpolate_multikeys` for details.
        self._tri_renum = None

    # __call__ and gradient docstrings are shared by all subclasses
    # (except, if needed, relevant additions).
    # However these methods are only implemented in subclasses to avoid
    # confusion in the documentation. 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:33,代码来源:triinterpolate.py

示例13: _mesh_plot

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def _mesh_plot(x, y, element_table, kwargs=None):
    """ Triplot of the mesh """
    if kwargs is None:
        kwargs = {}

    import matplotlib.pyplot as plt
    import matplotlib.tri as tri

    # Subtract 1 from element table to align with Python indexing
    t = tri.Triangulation(x, y, element_table-1)

    fig, ax = plt.subplots()
    ax.triplot(t, **kwargs)

    return fig, ax 
开发者ID:robjameswall,项目名称:dhitools,代码行数:17,代码来源:mesh.py

示例14: _filled_mesh_plot

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def _filled_mesh_plot(x, y, z, element_table, kwargs=None):
    """ Tricontourf of the mesh and input z"""
    if kwargs is None:
        kwargs = {}

    import matplotlib.pyplot as plt
    import matplotlib.tri as tri

    # Subtract 1 from element table to align with Python indexing
    t = tri.Triangulation(x, y, element_table-1)

    fig, ax = plt.subplots()
    tf = ax.tricontourf(t, z, **kwargs)

    return fig, ax, tf 
开发者ID:robjameswall,项目名称:dhitools,代码行数:17,代码来源:mesh.py

示例15: test_delaunay

# 需要导入模块: from matplotlib import tri [as 别名]
# 或者: from matplotlib.tri import Triangulation [as 别名]
def test_delaunay():
    # No duplicate points, regular grid.
    nx = 5
    ny = 4
    x, y = np.meshgrid(np.linspace(0.0, 1.0, nx), np.linspace(0.0, 1.0, ny))
    x = x.ravel()
    y = y.ravel()
    npoints = nx*ny
    ntriangles = 2 * (nx-1) * (ny-1)
    nedges = 3*nx*ny - 2*nx - 2*ny + 1

    # Create delaunay triangulation.
    triang = mtri.Triangulation(x, y)

    # The tests in the remainder of this function should be passed by any
    # triangulation that does not contain duplicate points.

    # Points - floating point.
    assert_array_almost_equal(triang.x, x)
    assert_array_almost_equal(triang.y, y)

    # Triangles - integers.
    assert_equal(len(triang.triangles), ntriangles)
    assert_equal(np.min(triang.triangles), 0)
    assert_equal(np.max(triang.triangles), npoints-1)

    # Edges - integers.
    assert_equal(len(triang.edges), nedges)
    assert_equal(np.min(triang.edges), 0)
    assert_equal(np.max(triang.edges), npoints-1)

    # Neighbors - integers.
    # Check that neighbors calculated by C++ triangulation class are the same
    # as those returned from delaunay routine.
    neighbors = triang.neighbors
    triang._neighbors = None
    assert_array_equal(triang.neighbors, neighbors)

    # Is each point used in at least one triangle?
    assert_array_equal(np.unique(triang.triangles), np.arange(npoints)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:42,代码来源:test_triangulation.py


注:本文中的matplotlib.tri.Triangulation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。