Python中的 Matplotlib.pyplot.tricontour()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。在 Pyplot 中可以使用各种图,包括线图、等高线图、直方图、散点图、3D 图等。
示例代码
# sample code
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [16, 4, 1, 8])
plt.show()
输出:
matplotlib.pyplot.tricontour()函数
matplotlib 库的 pyplot 模块中的tricontour()函数用于在非结构化三角形网格上绘制轮廓。
Syntax:
Parameters: This method accept the following parameters that are described below:
- x, y: These parameter are the x and y coordinates of the data which is to be plot.
- triangulation: This parameter is a matplotlib.tri.Triangulation object.
- Z: This parameter is is the array of values to contour, one per point in the triangulation.
- **kwargs: This parameter is Text properties that is used to control the appearance of the labels.
All remaining args
and kwargs
are the same as for matplotlib.pyplot. pcolor().
Returns: This returns the list of 2 Line2D containing following:
- The lines plotted for triangles edges.
- The markers plotted for triangles nodes
下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.tricontour()函数:
示例 #1:
matplotlib.pyplot.tricontour(*args, **kwargs)
输出:
示例 #2:
# 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, 5, 4],
[2, 6, 5], [4, 5, 7],
[5, 6, 8], [5, 8, 7],
[7, 8, 9], [1, 2, 5],
[2, 3, 6]]
triang = mtri.Triangulation(x, y, triangles)
z = np.cos(3 * x) * np.cos(6 * y)+np.sin(6 * x)
fig, axs = plt.subplots()
t = axs.tricontourf(triang, z)
axs.tricontour(triang, z, colors ='white')
fig.colorbar(t)
fig.suptitle('matplotlib.pyplot.tricontour() Example')
plt.show()
输出: