Python中的 Matplotlib.axes.Axes.text()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.text()函数
matplotlib 库的 axes 模块中的Axes.text()函数也用于将文本 s 添加到数据坐标中位置 x、y 的轴上。
Syntax:
Parameters: This method accept the following parameters that are described below:
- s: This parameter is the text to be add.
- xy: This parameter is the point (x, y) where text is to be placed.
- fontdict: This parameter is an optional parameter and a dictionary to override the default text properties.
- withdash: This parameter is also an optional parameter and creates a TextWithDash instance instead of a Text instance.
Returns: This method returns the text which is a created text instance..
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.text()函数:
示例 1:
Axes.text(self, x, y, s, fontdict=None, withdash=, **kwargs)
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.text(3, 4, 'GeeksforGeeks', style ='italic',
fontsize = 30, color ="green")
ax.set(xlim =(0, 8), ylim =(0, 8))
ax.set_title('matplotlib.axes.Axes.text() Example',
fontsize = 14, fontweight ='bold')
plt.show()
输出: