Python中的 Matplotlib.axes.Axes.contour()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.contour()函数
matplotlib 库的 axes 模块中的Axes.contour()函数用于绘制轮廓。轮廓绘制轮廓线。
Syntax:
Parameters: This method accept the following parameters that are described below:
- X, Y: These parameter are the coordinates of the values in Z.
- Z : This parameter is the height values over which the contour is drawn.
- levels : This parameter is used to determine the numbers and positions of the contour lines / regions.
Returns: This returns the following:
- c :This returns the QuadContourSet.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.contour()函数:
示例 1:
Axes.contour(self, *args, data=None, **kwargs)
contour([X, Y, ] Z, [levels], **kwargs)
输出:
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib
delta = 0.15
x = np.arange(-0.5, 2.5, delta)
y = np.arange(-1.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z = (np.exp(-X**2 - Y**2) - np.exp(-(X - 1)**2 - (Y - 1)**2))
fig1, ax1 = plt.subplots()
CS1 = ax1.contour(X, Y, Z)
fmt = {}
strs = ['1', '2', '3', '4', '5', '6', '7']
for l, s in zip(CS1.levels, strs):
fmt[l] = s
ax1.clabel(CS1, CS1.levels, inline = True,
fmt = fmt, fontsize = 10)
ax1.set_title('matplotlib.axes.Axes.contour() Example')
plt.show()
输出: