matplotlib.patches.ConnectionPatch#

class matplotlib.patches.ConnectionPatch(xyA, xyB, coordsA, coordsB=None, *, axesA=None, axesB=None, arrowstyle='-', connectionstyle='arc3', patchA=None, patchB=None, shrinkA=0.0, shrinkB=0.0, mutation_scale=10.0, mutation_aspect=None, clip_on=False, **kwargs)[source]#

基类:FancyArrowPatch

连接两个点(可能在不同坐标系中)的补丁。

连接 coordsA 中的点 xyAcoordsB 中的点 xyB

有效键为

描述

arrowstyle(箭头样式)

箭头样式

connectionstyle(连接样式)

连接样式

relpos(相对位置)

默认为 (0.5, 0.5)

patchA

默认为文本的边界框

patchB

默认为 None

shrinkA

默认为 2 点

shrinkB

默认为 2 点

mutation_scale(突变比例)

默认为文本大小(以点为单位)

mutation_aspect(突变纵横比)

默认为 1。

?

适用于 matplotlib.patches.PathPatch 的任何键

coordsAcoordsB 是字符串,指示 xyAxyB 的坐标。

属性

描述

'figure points'(图形点)

从图形左下角算起的点

'figure pixels'(图形像素)

从图形左下角算起的像素

'figure fraction'(图形比例)

0, 0 是图形左下角,1, 1 是右上角

'subfigure points'(子图点)

从子图左下角算起的点

'subfigure pixels'(子图像素)

从子图左下角算起的像素

'subfigure fraction'(子图比例)

子图的比例,0, 0 是左下角。

'axes points'(坐标系点)

从坐标系左下角算起的点

'axes pixels'(坐标系像素)

从坐标系左下角算起的像素

'axes fraction'(坐标系比例)

0, 0 是坐标系左下角,1, 1 是右上角

'data'(数据)

使用被标注对象的坐标系(默认)

'offset points'(偏移点)

xy 值偏移(以点为单位)

'polar'(极坐标)

您可以为标注指定 thetar,即使在笛卡尔坐标图中也是如此。请注意,如果您使用的是极坐标系,则无需为坐标系指定极坐标,因为这是原生的“数据”坐标系。

或者,它们可以设置为任何有效的 Transform

请注意,对于父图形,'subfigure pixels' 和 'figure pixels' 是相同的,因此希望代码可在子图中使用的用户可以使用 'subfigure pixels'。

注意

在两个 Axes 实例之间使用 ConnectionPatch受限布局不直接兼容。请将艺术家直接添加到Figure中,而不是添加到特定的 Axes 中,或者使用 con.set_in_layout(False) 将其从布局中排除。

fig, ax = plt.subplots(1, 2, constrained_layout=True)
con = ConnectionPatch(..., axesA=ax[0], axesB=ax[1])
fig.add_artist(con)
draw(renderer)[source]#

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

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

参数:
rendererRendererBase 子类。

备注

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

get_annotation_clip()[source]#

返回裁剪行为。

有关返回值的含义,请参阅 set_annotation_clip

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, annotation_clip=<UNSET>, antialiased=<UNSET>, arrowstyle=<UNSET>, capstyle=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, connectionstyle=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, fill=<UNSET>, gid=<UNSET>, hatch=<UNSET>, hatch_linewidth=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, mutation_aspect=<UNSET>, mutation_scale=<UNSET>, patchA=<UNSET>, patchB=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, positions=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)[source]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter(聚合过滤器)

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

alpha(透明度)

浮点数或 None

animated(动画)

布尔值

annotation_clip(标注裁剪)

布尔值或 None

antialiasedaa(抗锯齿)

布尔值或 None

arrowstyle(箭头样式)

[ '-' | '<-' | '->' | '<->' | '<|-' | '-|>' | '<|-|>' | ']-' | '-[' | ']-[' | '|-|' | ']->' | '<-[' | 'simple' | 'fancy' | 'wedge' ]

capstyle(端点样式)

CapStyle 或 {'butt', 'projecting', 'round'}

clip_box(裁剪框)

BboxBase 或 None

clip_on(开启裁剪)

布尔值

clip_path(裁剪路径)

Patch 或 (Path, Transform) 或 None

color(颜色)

color(颜色)

connectionstyle(连接样式)

[ 'arc3' | 'angle3' | 'angle' | 'arc' | 'bar' ]

edgecolorec(边框颜色)

颜色 或 None

facecolorfc(填充颜色)

颜色 或 None

figure(图形)

FigureSubFigure

fill(填充)

布尔值

gid

str(字符串)

hatch(填充图案)

{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}

hatch_linewidth(填充图案线宽)

未知

in_layout(在布局中)

布尔值

joinstyle(连接样式)

JoinStyle 或 {'miter', 'round', 'bevel'}

label(标签)

object(对象)

linestylels(线型)

{'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

linewidthlw(线宽)

浮点数或 None

mouseover(鼠标悬停)

布尔值

mutation_aspect(突变纵横比)

浮点数

mutation_scale(突变比例)

浮点数

patchA

patches.Patch

patchB

patches.Patch

path_effects(路径效果)

AbstractPathEffect 列表

picker(选择器)

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

positions(位置)

未知

rasterized(光栅化)

布尔值

sketch_params(草图参数)

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

snap(对齐)

布尔值或 None

transform(变换)

变换

url

str(字符串)

visible(可见性)

布尔值

zorder(Z轴顺序)

浮点数

set_annotation_clip(b)[source]#

设置标注的裁剪行为。

参数:
b布尔值或 None
  • True:当 self.xy 在 Axes 外部时,标注将被裁剪。

  • False:标注将始终绘制。

  • None:当 self.xy 在 Axes 外部且 self.xycoords == "data" 时,标注将被裁剪。

使用 matplotlib.patches.ConnectionPatch 的示例#

多坐标轴动画

多坐标轴动画

饼中条形图

饼中条形图

约束布局指南

约束布局指南

注解

注解