Python中的 Matplotlib.axes.Axes.annotate()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.annotate()函数
matplotlib 库的axes 模块中的Axes.annotate()函数也用于用文本文本注释点xy。换句话说,我曾经将文本放置在xy 处。
Syntax:
Parameters: This method accept the following parameters that are described below:
- s: This parameter is the text of the annotation.
- xy: This parameter is the point (x, y) to annotate.
- xytext: This parameter is an optional parameter. It is The position (x, y) to place the text at.
- xycoords: This parameter is also an optional parameter and contains the string value.
- textcoords: This parameter contains the string value.Coordinate system that xytext is given, which may be different than the coordinate system used for xy
- arrowprops : This parameter is also an optional parameter and contains dict type.Its default value is None.
- annotation_clip : This parameter is also an optional parameter and contains boolean value.Its default value is None which behaves as True.
Returns: This method returns the annotation.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.annotate()函数:
示例 1:
Axes.annotate(self, s, xy, *args, **kwargs)
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
fig, ax1 = plt.subplots()
t = np.arange(4, 50., 1)
s = np.cos(np.pi * t)**3- np.sin(3 * np.pi * t)**2
ax1.plot(t, s, lw = 2)
ax1.annotate('Starting', xy =(3.3, 1),
xytext =(3, 1.8),
arrowprops = dict(facecolor ='green',
shrink = 0.05), )
ax1.set_ylim(-2, 2)
ax1.set_title('matplotlib.axes.Axes.annotate() Example')
plt.show()
输出: