matplotlib.pyplot.triplot()函数

您所在的位置:网站首页 网格三角函数题 matplotlib.pyplot.triplot()函数

matplotlib.pyplot.triplot()函数

2024-07-14 20:49| 来源: 网络整理| 查看: 265

matplotlib.pyplot.triplot()函数

Matplotlib是Python中的一个库,它是NumPy库的数值-数学扩展。Pyplot是一个基于状态的Matplotlib模块接口,该模块提供了一个类似matlab的接口。Pyplot中可以使用的绘图有直线图、轮廓图、直方图、散点图、三维图等。

matplotlib.pyplot.triplot() Function:

使用matplotlib库pyplot模块中的triplot()函数绘制非结构化三角形网格作为线和/或标记。

语法:matplotlib.pyplot.triplot (* args, * * kwargs)

参数:该方法接受如下参数说明:

x, y:这些参数是要绘制的数据的x和y坐标。 triangulation:这个参数是一个matplotlib.tri.Triangulation对象。 **kwargs:这个参数是Text属性,用于控制标签的外观。

所有剩余的参数和kwargs与matplotlib.pyplot.plot()相同。

返回2个Line2D的列表,包含以下内容:

画出三角形边的线。 标记为三角形节点

下面的例子演示了matplotlib.pyplot.triplot()函数在matplotlib.pyplot中的作用:

示例1 # Implementation of matplotlib function import matplotlib.pyplot as plt import matplotlib.tri as mtri import numpy as np     # Create triangulation. x = np.asarray([0, 1, 2, 3, 0.5, 1.5,                 2.5, 1, 2, 1.5])    y = np.asarray([0, 0, 0, 0, 1.0,                 1.0, 1.0, 2, 2, 3.0])    triangles = [[0, 1, 4], [1, 2, 5],               [2, 3, 6], [1, 5, 4],               [2, 6, 5], [4, 5, 7],              [5, 6, 8], [5, 8, 7],              [7, 8, 9]]    triang = mtri.Triangulation(x, y, triangles) z = np.cos(1.5 * x) * np.cos(1.5 * y)     plt.tricontourf(triang, z) plt.triplot(triang, 'go-')     plt.title('matplotlib.pyplot.triplot() Example') plt.show()

输出:

matplotlib.pyplot.triplot()函数

示例2 # Implementation of matplotlib function import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np     n_angles = 24 n_radii = 9 min_radius = 0.5 radii = np.linspace(min_radius, 0.9,                     n_radii)     angles = np.linspace(0, 3 * np.pi, n_angles,                       endpoint = False)    angles = np.repeat(angles[..., np.newaxis],                     n_radii, axis = 1)    angles[:, 1::2] += np.pi / n_angles     x = (radii * np.cos(angles)).flatten() y = (radii * np.sin(angles)).flatten() triang = tri.Triangulation(x, y)     triang.set_mask(np.hypot(x[triang.triangles].mean(axis = 1),                          y[triang.triangles].mean(axis = 1))                 < min_radius)    plt.triplot(triang, 'go-', lw = 1) plt.title('matplotlib.pyplot.triplot() Example') plt.show()

输出:

matplotlib.pyplot.triplot()函数



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3