mpl_toolkits.axisartist.axis_artist.LabelBase#

class mpl_toolkits.axisartist.axis_artist.LabelBase(*args, **kwargs)[源代码]#

基类:Text

AxisLabelTickLabels 的基类。文本的位置和角度由 offset_ref_angle、text_ref_angle 和 offset_radius 属性计算得出。

x, y 处创建带有字符串 textText 实例。

文本相对于锚点 (x, y) 根据 horizontalalignment(默认:'left')和 verticalalignment(默认:'baseline')进行对齐。另请参阅 文本对齐

虽然 Text 接受 'label' 关键字参数,但默认情况下它不会添加到图例的句柄中。

有效的关键字参数有:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

antialiased

布尔值

backgroundcolor

color

bbox

包含 FancyBboxPatch 属性的字典,或为 None

clip_box

未知

clip_on

未知

clip_path

未知

colorc

color

figure

FigureSubFigure

fontfamilyfamilyfontname

{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'}

fontfeatures

字符串列表、字符串元组或 None

fontpropertiesfontfont_properties

font_manager.FontPropertiesstrpathlib.Path

fontsizesize

float 或 {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}

fontstretchstretch

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

fontstylestyle

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

fontvariantvariant

{'normal', 'small-caps'}

fontweightweight

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

gid

str

horizontalalignmentha

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

in_layout

布尔值

label

object

language

str 或 None

linespacing

'normal' 或浮点数,默认:'normal'

math_fontfamily

str

mouseover

布尔值

multialignmentma

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

parse_math

布尔值

path_effects

AbstractPathEffect 列表

picker

None 或 布尔值 或 浮点数 或 可调用对象

position

(浮点数, 浮点数)

rasterized

布尔值

rotation

float 或 {'vertical', 'horizontal'}

rotation_mode

{None, 'default', 'anchor', 'xtick', 'ytick'}

sketch_params

(scale: 浮点数, length: 浮点数, randomness: 浮点数)

snap

布尔值或 None

text

object

transform

变换

transform_rotates_text

布尔值

url

str

usetex

布尔值,默认值:rcParams["text.usetex"](默认:False

verticalalignmentva

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

visible

布尔值

wrap

布尔值

x

浮点数

y

浮点数

zorder

浮点数

draw(renderer)[源代码]#

使用给定的渲染器绘制 Artist(及其子对象)。

如果该艺术家对象不可见(Artist.get_visible 返回 False),则此操作无效。

参数:
rendererRendererBase 子类。

备注

此方法在 Artist 子类中被覆盖。

get_window_extent(renderer=None)[源代码]#

返回以显示单位表示的、包围文本的 Bbox

除了内部使用外,这对于在网页上的 png 文件中指定可点击区域也很有用。

参数:
renderer渲染器,可选

计算边界框需要渲染器。如果艺术家(Artist)已经被绘制,渲染器会被缓存;因此,只有在第一次绘制之前调用 get_window_extent 时才需要传递此参数。实际上,通常更简单的方法是先触发绘制,例如调用 draw_without_renderingplt.show()

dpifloat, 可选

计算 bbox 的 dpi 值,默认为 self.get_figure(root=True).dpi不是渲染器 dpi);如果需要匹配使用自定义 dpi 值保存的图形区域,则应设置该值。

property locs_angles_labels[源代码]#

[已弃用]

备注

自 3.11 版本起弃用

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, backgroundcolor=<UNSET>, bbox=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, fontfamily=<UNSET>, fontfeatures=<UNSET>, fontproperties=<UNSET>, fontsize=<UNSET>, fontstretch=<UNSET>, fontstyle=<UNSET>, fontvariant=<UNSET>, fontweight=<UNSET>, gid=<UNSET>, horizontalalignment=<UNSET>, in_layout=<UNSET>, label=<UNSET>, language=<UNSET>, linespacing=<UNSET>, math_fontfamily=<UNSET>, mouseover=<UNSET>, multialignment=<UNSET>, parse_math=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, rasterized=<UNSET>, rotation=<UNSET>, rotation_mode=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, text=<UNSET>, transform=<UNSET>, transform_rotates_text=<UNSET>, url=<UNSET>, usetex=<UNSET>, verticalalignment=<UNSET>, visible=<UNSET>, wrap=<UNSET>, x=<UNSET>, y=<UNSET>, zorder=<UNSET>)[源代码]#

一次性设置多个属性。

a.set(a=A, b=B, c=C)

等同于

a.set_a(A)
a.set_b(B)
a.set_c(C)

除全名属性外,还支持别名,例如 set(lw=2) 等同于 set(linewidth=2),但同时传入两者会报错。

各个 setter 的调用顺序与 set() 中的参数顺序一致。然而,大多数属性并不相互依赖,因此顺序通常无关紧要。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

antialiased

布尔值

backgroundcolor

color

bbox

包含 FancyBboxPatch 属性的字典,或为 None

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

colorc

color

figure

FigureSubFigure

fontfamilyfamilyfontname

{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'}

fontfeatures

字符串列表、字符串元组或 None

fontpropertiesfontfont_properties

font_manager.FontPropertiesstrpathlib.Path

fontsizesize

float 或 {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}

fontstretchstretch

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

fontstylestyle

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

fontvariantvariant

{'normal', 'small-caps'}

fontweightweight

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

gid

str

horizontalalignmentha

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

in_layout

布尔值

label

object

language

str 或 None

linespacing

'normal' 或浮点数,默认:'normal'

math_fontfamily

str

mouseover

布尔值

multialignmentma

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

parse_math

布尔值

path_effects

AbstractPathEffect 列表

picker

None 或 布尔值 或 浮点数 或 可调用对象

position

(浮点数, 浮点数)

rasterized

布尔值

rotation

float 或 {'vertical', 'horizontal'}

rotation_mode

{None, 'default', 'anchor', 'xtick', 'ytick'}

sketch_params

(scale: 浮点数, length: 浮点数, randomness: 浮点数)

snap

布尔值或 None

text

object

transform

变换

transform_rotates_text

布尔值

url

str

usetex

布尔值,默认值:rcParams["text.usetex"](默认:False

verticalalignmentva

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

visible

布尔值

wrap

布尔值

x

浮点数

y

浮点数

zorder

浮点数