matplotlib.patches.Rectangle#

class matplotlib.patches.Rectangle(xy, width, height, *, angle=0.0, rotation_point='xy', **kwargs)[源代码]#

基类:Patch

一个通过锚点 xy 及其 宽度高度 定义的矩形。

该矩形在 x 方向上从 xy[0] 延伸到 xy[0] + width,在 y 方向上从 xy[1] 延伸到 xy[1] + height

:                +------------------+
:                |                  |
:              height               |
:                |                  |
:               (xy)---- width -----+

可以将 xy 想象成左下角,但 *xy* 实际是哪个角取决于坐标轴的方向以及 *宽度* 和 *高度* 的正负;例如,如果 x 轴反转或 *宽度* 为负,*xy* 将是右下角。

参数:
xy(float, float)

锚点。

width浮点数

矩形宽度。

heightfloat

矩形高度。

anglefloat, 默认值: 0

围绕旋转点逆时针旋转的度数。

rotation_point{'xy', 'center', (number, number)}, default: 'xy'

如果为 `'xy'`,则围绕锚点旋转。如果为 `'center'`,则围绕中心旋转。如果是数字的 2 元组,则围绕此坐标旋转。

其他参数:
**kwargsPatch 属性

属性

描述

agg_filter

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

alpha

未知

animated

布尔值

antialiasedaa

布尔值或 None

capstyle

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

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

color

color

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

布尔值

path_effects

list of AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

zorder

浮点数

get_angle()[源代码]#

获取旋转角度(以度为单位)。

get_bbox()[源代码]#

返回 Bbox

get_center()[源代码]#

返回矩形的中心。

get_corners()[源代码]#

返回矩形的角点,从 (x0, y0) 开始逆时针移动。

get_height()[源代码]#

返回矩形的高度。

get_patch_transform()[源代码]#

返回将补丁坐标映射到数据坐标的 Transform 实例。

例如,可以通过提供单位圆的坐标,并使用一个将坐标(补丁坐标)缩放5倍的变换,来定义一个表示半径为5的圆形补丁。

get_path()[源代码]#

返回矩形的顶点。

get_width()[源代码]#

返回矩形的宽度。

get_x()[源代码]#

返回矩形的左坐标。

get_xy()[源代码]#

以元组形式返回矩形的左下坐标。

get_y()[源代码]#

返回矩形的下坐标。

property rotation_point#

补丁的旋转点。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, angle=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, bounds=<UNSET>, capstyle=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, fill=<UNSET>, gid=<UNSET>, hatch=<UNSET>, hatch_linewidth=<UNSET>, height=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, x=<UNSET>, xy=<UNSET>, y=<UNSET>, zorder=<UNSET>)[源代码]#

一次性设置多个属性。

支持的属性包括:

属性

描述

agg_filter

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

alpha

浮点数或 None

angle

未知

animated

布尔值

antialiasedaa

布尔值或 None

bounds

(左,下,宽,高)

capstyle

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

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

color

color

edgecolorec

颜色 或 None

facecolorfc

颜色 或 None

figure

FigureSubFigure

fill

布尔值

gid

str

hatch

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

hatch_linewidth

未知

height

未知

in_layout

布尔值

joinstyle

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

label

object

linestylels

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

linewidthlw

浮点数或 None

mouseover

布尔值

path_effects

list of AbstractPathEffect

picker

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

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

transform

变换

url

str

visible

布尔值

width

未知

x

未知

xy

(浮点数, 浮点数)

y

未知

zorder

浮点数

set_angle(angle)[源代码]#

设置旋转角度(以度为单位)。

旋转是围绕 *xy* 逆时针进行的。

set_bounds(*args)[源代码]#

设置矩形的边界为 *左*、*下*、*宽度*、*高度*。

这些值可以作为单独的参数或作为元组传递。

set_bounds(left, bottom, width, height)
set_bounds((left, bottom, width, height))
set_height(h)[源代码]#

设置矩形的高度。

set_width(w)[源代码]#

设置矩形的宽度。

set_x(x)[源代码]#

设置矩形的左坐标。

set_xy(xy)[源代码]#

设置矩形的左下坐标。

参数:
xy(float, float)
set_y(y)[源代码]#

设置矩形的下坐标。

property xy#

以元组形式返回矩形的左下坐标。

使用 matplotlib.patches.Rectangle 的示例#

插入定位器演示

插入定位器演示

命名颜色列表

命名颜色列表

选择事件演示

选择事件演示

视图限制

视图限制

识别艺术家是否相交

识别艺术家是否相交

Matplotlib 标志

Matplotlib 标志

Matplotlib 艺术家参考

Matplotlib 艺术家参考

孵化图案样式参考

孵化图案样式参考

辛顿图

辛顿图

使用 PatchCollection 从误差条创建框

使用 PatchCollection 从误差条创建框

直方图

直方图

样式表参考

样式表参考

文本旋转模式

文本旋转模式

文本对齐

文本对齐

图形坐标轴简单自定义

图形坐标轴简单自定义

艺术家测试

艺术家测试

菜单

菜单

Artist 教程

Artist 教程

变换教程

变换教程

图例指南

图例指南

指定颜色

指定颜色

文本属性和布局

文本属性和布局