matplotlib.patches.Rectangle#

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

基类:Patch

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

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

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

可以将 xy 想象为左下角,但 xy 实际上是哪个角取决于轴的方向和 widthheight 的符号;例如,如果 x 轴反转或 width 为负,xy 将是右下角。

参数:
xy(浮点数, 浮点数)

锚点。

宽度float

矩形的宽度。

高度float

矩形高度。

角度float, 默认值: 0

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

旋转点{'xy', 'center', (number, number)}, 默认: 'xy'

如果 'xy',围绕锚点旋转。如果 'center',围绕中心旋转。如果是两个数字的元组,围绕这个坐标旋转。

其他参数:
**kwargs : Patch 属性补丁属性

属性

描述

agg_filter

一个过滤函数,该函数接收一个 (m, n, 3) 浮点数组和一个 dpi 值,并返回一个 (m, n, 3) 数组和两个从图像左下角开始的偏移量

alpha

未知

animated

布尔

抗锯齿 或 aa

布尔值或无

capstyle

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

clip_box

BboxBase 或 None

clip_on

布尔

clip_path

补丁或(路径,变换)或无

颜色

color

edgecolor 或 ec

color or None

facecolor 或 fc

color or None

figure

FigureSubFigure

填充

布尔

gid

str

hatch

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

in_layout

布尔

joinstyle

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

标签

对象

linestyle 或 ls

{'-', '--', '-.', ':', '', (偏移, 开-关-序列), ...}

linewidth 或 lw

浮点数或无

鼠标悬停

布尔

路径效果

AbstractPathEffect 的列表

picker

None 或 bool 或 float 或 callable

光栅化

布尔

sketch_params

(scale: float, length: float, randomness: float)

snap

布尔值或无

transform

Transform

url

str

可见

布尔

zorder

float

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

标量或无

angle

未知

animated

布尔

抗锯齿 或 aa

布尔值或无

边界

(左,底,宽,高)

capstyle

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

clip_box

BboxBase 或 None

clip_on

布尔

clip_path

补丁或(路径,变换)或无

颜色

color

edgecolor 或 ec

color or None

facecolor 或 fc

color or None

figure

FigureSubFigure

填充

布尔

gid

str

hatch

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

高度

未知

in_layout

布尔

joinstyle

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

标签

对象

linestyle 或 ls

{'-', '--', '-.', ':', '', (偏移, 开-关-序列), ...}

linewidth 或 lw

浮点数或无

鼠标悬停

布尔

路径效果

AbstractPathEffect 的列表

picker

None 或 bool 或 float 或 callable

光栅化

布尔

sketch_params

(scale: float, length: float, randomness: float)

snap

布尔值或无

transform

Transform

url

str

可见

布尔

宽度

未知

x

未知

xy

(浮点数, 浮点数)

y

未知

zorder

float

set_angle(angle)[源代码][源代码]#

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

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

set_bounds(*args)[源代码][源代码]#

将矩形的边界设置为 leftbottomwidthheight

这些值可以作为单独的参数传递,也可以作为一个元组传递:

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(浮点数, 浮点数)
set_y(y)[源代码][源代码]#

设置矩形的底部坐标。

property xy#

返回矩形的左下角坐标,作为元组。

使用 matplotlib.patches.Rectangle 的示例#

使用 PatchCollection 从误差条创建框

Create boxes from error bars using PatchCollection

直方图

Histograms

文本旋转模式

Text rotation mode

文本对齐

Text alignment

命名颜色列表

List of named colors

Matplotlib 艺术家的参考

Reference for Matplotlib artists

Hatch 样式参考

Hatch style reference

样式表引用

Style sheets reference

插入定位器演示

Inset locator demo

选择事件演示

Pick event demo

视图限制

Viewlims

识别艺术家是否相交

Identify whether artists intersect

Matplotlib 标志

Matplotlib logo

Hinton 图

Hinton diagrams

图 轴 自定义 简单

Fig Axes Customize Simple

艺术家测试

Artist tests

菜单

Menu

艺术家教程

Artist tutorial

变换教程

Transformations Tutorial

图例指南

Legend guide

指定颜色

Specifying colors

文本属性和布局

Text properties and layout