matplotlib.pyplot.text#
- matplotlib.pyplot.text(x, y, s, fontdict=None, **kwargs)[源代码][源代码]#
向 Axes 添加文本。
在数据坐标中的位置 x, y 处向 Axes 添加文本 s,默认的
horizontalalignment
为left
,verticalalignment
为baseline
。参见 文本对齐。- 参数:
- x, y浮动
文本放置的位置。默认情况下,这是在数据坐标中。可以使用 transform 参数更改坐标系。
- sstr
文本。
- fontdict字典, 默认: None
不鼓励
不鼓励使用 fontdict。参数应作为单独的关键字参数传递,或使用字典解包
text(..., **fontdict)
。一个用于覆盖默认文本属性的字典。如果 fontdict 为 None,则默认值由
rcParams
决定。
- 返回:
- 其他参数:
- **kwargs :
Text
属性。文本属性。 其他杂项文本参数。
属性
描述
一个过滤函数,它接收一个 (m, n, 3) 浮点数组和一个 dpi 值,并返回一个 (m, n, 3) 数组和图像左下角的两个偏移量
标量或无
布尔
布尔
带有
patches.FancyBboxPatch
属性的字典未知
未知
未知
颜色
或 cfontfamily
或 family 或 fontname{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'}
fontproperties
或 font 或 font_properties字体大小
或大小float 或 {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}
fontstretch
或 stretch{一个数值范围在0-1000之间, '超压缩', '特压缩', '压缩', '半压缩', '正常', '半扩展', '扩展', '特扩展', '超扩展'}
fontstyle
或样式{'normal', 'italic', 'oblique'}
fontvariant
或 variant{'normal', 'small-caps'}
fontweight
或 weight{一个数值范围在0-1000,'超轻','轻','正常','常规','书','中等','罗马','半粗','半粗','半','粗','重','特粗','黑'}
str
horizontalalignment
或 ha{'left', 'center', 'right'}
布尔
对象
浮动(字体大小的倍数)
str
布尔
multialignment
或 ma{'left', 'right', 'center'}
布尔
None 或 bool 或 float 或 callable
(浮点数, 浮点数)
布尔
浮点数或 {'垂直', '水平'}
{None, 'default', 'anchor'}
(scale: float, length: float, randomness: float)
布尔值或无
对象
布尔
str
bool, 默认值:
rcParams["text.usetex"]
(default:False
)垂直对齐
或 va{'baseline', 'bottom', 'center', 'center_baseline', 'top'}
布尔
布尔
浮动
浮动
浮动
- **kwargs :
注释
备注
这是
axes.Axes.text
的 pyplot 包装器。示例
可以使用单独的关键字参数来覆盖任何给定的参数:
>>> text(x, y, s, fontsize=12)
默认的变换指定文本在数据坐标中,或者,您可以指定文本在轴坐标中((0, 0) 是左下角,(1, 1) 是右上角)。下面的示例将文本放置在 Axes 的中心:
>>> text(0.5, 0.5, 'matplotlib', horizontalalignment='center', ... verticalalignment='center', transform=ax.transAxes)
你可以通过使用关键字 bbox 在文本实例周围放置一个矩形框(例如,设置背景颜色)。bbox 是一个
Rectangle
属性的字典。例如:>>> text(x, y, s, bbox=dict(facecolor='red', alpha=0.5))