当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python matplotlib Axes.text用法及代码示例


本文简要介绍 python 语言中 matplotlib.axes.Axes.text 的用法。

用法

Axes.text(x, y, s, fontdict=None, **kwargs)

将文本添加到轴。

将文本 s 添加到数据坐标中位置 xy 的轴上。

参数
x, y 浮点数

放置文本的位置。默认情况下,这是在数据坐标中。可以使用transform 参数更改坐标系。

s str

文本。

fontdict 字典,默认值:无
灰心

不鼓励使用fontdict。参数应作为单独的关键字参数或使用 dictionary-unpacking text(..., **fontdict) 传递。

用于覆盖默认文本属性的字典。如果 fontdict 为 None,则默认值由 rcParams 确定。

返回
Text

创建的 Text 实例。

其他参数
**kwargs Text 属性。

其他杂项文本参数。

属性

说明

agg_filter

一个过滤器函数,它接受一个 (m, n, 3) 浮点数组和一个 dpi 值,并返回一个 (m, n, 3) 数组和距图像左下角的两个偏移量

alpha

标量或无

animated

bool

antialiased

bool

backgroundcolor

color

matplotlib.text.Text.set_bbox

带有 patches.FancyBboxPatch 属性的字典

clip_box

unknown

clip_on

unknown

clip_path

unknown

color 或 c

color

figure

Figure

fontfamily 或系列或字体名称

{字体名称,'serif','sans-serif','cursive', 'fantasy', 'monospace'}

fontproperties 或字体或font_properties

font_manager.FontProperties str pathlib.Path

fontsize 或尺寸

浮点数或{'xx-small'、'x-small'、'small', 'medium', 'large'、'x-large'、'xx-large'}

fontstretch 或拉伸

{0-1000 范围内的数值、'ultra-condensed'、'extra-condensed'、'condensed'、'semi-condensed'、'normal'、'semi-expanded'、'expanded'、'extra-expanded'、'ultra-expanded'}

fontstyle 或款式

{'normal', 'italic', 'oblique'}

fontvariant 或变体

{'normal','small-caps'}

fontweight 或重量

{0-1000 范围内的数值,'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy','extra bold','black'}

gid

str

horizontalalignment 或公顷

{'left', 'center', 'right'}

in_layout

bool

label

object

linespacing

浮点数(字体大小的倍数)

math_fontfamily

str

mouseover

bool

multialignment 或 ma

{'left', 'right', 'center'}

parse_math

bool

path_effects

AbstractPathEffect 列表

picker

None 或 bool 或 float 或可调用

position

(浮点数,浮点数)

rasterized

bool

rotation

浮点数或 {'vertical', 'horizontal'}

rotation_mode

{无,'default', 'anchor'}

sketch_params

(比例:浮点数,长度:浮点数,随机性:浮点数)

snap

布尔或无

text

object

transform

Transform

transform_rotates_text

bool

url

str

usetex

布尔或无

verticalalignment 或 va

{'bottom', 'baseline', 'center', 'center_baseline', 'top'}

visible

bool

wrap

bool

x

float

y

float

zorder

float

例子

单个关键字参数可用于覆盖任何给定参数:

>>> text(x, y, s, fontsize=12)

默认转换指定文本在数据坐标中,或者,您可以在轴坐标中指定文本((0, 0) 是左下角, (1, 1) 是右上角)。下面的示例将文本放置在轴的中心:

>>> 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))

相关用法


注:本文由纯净天空筛选整理自skytowner.com大神的英文原创作品 matplotlib.axes.Axes.text。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。