Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。 Pyplot是Matplotlib模塊的基於狀態的接口,該模塊提供了MATLAB-like接口。
Matplotlib.pyplot.tricontourf()
matplotlib庫的pyplot模塊中的tricontourf()函數用於在非結構化三角形網格上繪製輪廓。
用法: matplotlib.pyplot.tricontourf(\*args, \*\*kwargs)
參數:此方法接受下麵描述的以下參數:
- x, y:這些參數是要繪製的數據的x和y坐標。
- triangulation:此參數是matplotlib.tri.Triangulation對象。
- Z:此參數是輪廓值的數組,三角測量中每個點一個。
- **kwargs:此參數是文本屬性,用於控製標簽的外觀。
其餘所有args和kwargs與matplotlib.pyplot.plot()相同。
返回值:這將返回包含以下內容的2 Line2D的列表:
- 為三角形邊繪製的線。
- 為三角形節點繪製的標記
注意:tricontourf-only關鍵字參數是抗鋸齒的,它是布爾啟用抗鋸齒,用於非結構化三角形網格的輪廓中。
以下示例說明了matplotlib.pyplot中的matplotlib.pyplot.tricontourf()函數:
範例1:
Python3
#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, 0, 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(2.5 * x*x) + np.sin(2.5 * x*x)
t = plt.tricontourf(triang, z)
plt.title('matplotlib.pyplot.tricontourf() Example\n',
fontsize=14, fontweight='bold')
plt.show()
輸出:
範例2:
Python3
#Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np
n_angles = 60
n_radii = 10
min_radius = 0.35
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0, np.pi, n_angles, endpoint = False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis = 1)
angles[:, 1::2] += np.pi / n_angles
x = (10 * radii * np.cos(angles)).flatten()
y = (10 * radii * np.sin(angles)).flatten()
z = (np.cos(4*(radii)**2) * np.sin((angles)**2)).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)
tcf = plt.tricontourf(triang, z)
plt.colorbar(tcf)
plt.title('matplotlib.pyplot.tricontourf() Example\n',
fontsize=14, fontweight='bold')
plt.show()
輸出:
相關用法
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.pyplot.tricontourf() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。