Python中的 Matplotlib.axes.Axes.clabel()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.clabel()函数
matplotlib 库的 axes 模块中的Axes.clabel()函数用于标记等高线图。
Syntax:
Parameters: This method accept the following parameters that are described below:
- cs : This parameter is the ContourSet to label.
- fontsize : This parameter is the size in points.
- gridsize : This parameter represents the number of hexagons in the x-direction or both direction.
- colors : This parameter is used to color the label
- inline : This parameter removes the underlying contour where the label is placed.
- inline_spacing : This parameter is space in pixels to leave on each side of label when placing inline.
- marginals : This parameter is used to plot the marginal density as colormapped rectangles along the bottom of the x-axis and left of the y-axis.
- fmt : This parameter is the format string for the label.
- manual : This parameter is used to place the contuor label using mouse.
- rightside_up : This parameter is used to rotate the label.
- use_clabeltext : This parameter is used to create labels. ClabelText recalculates rotation angles of texts.
Returns: This returns the following:
- labels:This returns the list of Text instances for the labels.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.clabel()函数:
示例 1:
Axes.clabel(self, CS, *args, **kwargs)
输出:
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib
delta = 2.5
x = np.arange(-13.0, 13.0, delta)
y = np.arange(-12.0, 12.0, delta)
X, Y = np.meshgrid(x, y)
Z = (np.exp(-X**2 - Y**2) - np.exp(-(X - 1)**2 - (Y - 1)**2)) * 3
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.clabel() Example')
plt.show()
输出: