matplotlib.pyplot.axline#

matplotlib.pyplot.axline(xy1, xy2=None, *, slope=None, **kwargs)[源代码]#

添加一条无限长的直线。

该直线可以通过两个点 xy1xy2 定义,也可以通过一个点 xy1 和一个 slope 定义。

这会在“屏幕上”绘制一条直线,而不考虑 x 和 y 轴的刻度,因此也适用于在半对数图中绘制指数衰减,在双对数图中绘制幂律等。然而,slope 仅应与线性刻度一起使用;对于所有其他刻度,它没有明确的含义,因此行为是未定义的。对于非线性刻度,请使用点 xy1xy2 来指定直线。

transform 关键字参数仅适用于点 xy1xy2slope(如果给定)始终在数据坐标中。例如,这可以与 ax.transAxes 一起使用,以绘制具有固定斜率的网格线。

参数:
xy1, xy2(float, float)

直线通过的点。必须提供 xy2slope

slopefloat, optional

直线的斜率。必须提供 xy2slope

返回:
AxLine
其他参数:
**kwargs

有效的 kwargs 是 Line2D 属性

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

antialiasedaa

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

colorc

color

dash_capstyle

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

dash_joinstyle

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

dashes

浮点数序列(点中的开/关墨迹)或 (None, None)

data

(2, N) 数组或两个一维数组

drawstyleds

{'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'},默认值: 'default'

figure

FigureSubFigure

fillstyle

{'full', 'left', 'right', 'bottom', 'top', 'none'}

gapcolor

颜色 或 None

gid

str

in_layout

布尔值

label

object

linestylels

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

linewidthlw

浮点数

marker

marker style string, PathMarkerStyle

markeredgecolormec

color

markeredgewidthmew

浮点数

markerfacecolormfc

color

markerfacecoloraltmfcalt

color

markersizems

浮点数

markevery

None 或 int 或 (int, int) 或 slice 或 list[int] 或 float 或 (float, float) 或 list[bool]

mouseover

布尔值

path_effects

list of AbstractPathEffect

picker

浮点数或 callable[[Artist, Event], tuple[bool, dict]]

pickradius

浮点数

rasterized

布尔值

sketch_params

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

snap

布尔值或 None

solid_capstyle

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

solid_joinstyle

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

transform

未知

url

str

visible

布尔值

xdata

一维数组

ydata

一维数组

zorder

浮点数

另请参阅

axhline

用于水平线

axvline

用于垂直线

备注

注意

这是 pyplot 封装,对应于 axes.Axes.axline

示例

绘制一条通过 (0, 0) 和 (1, 1) 的粗红色直线

>>> axline((0, 0), (1, 1), linewidth=4, color='r')

使用 matplotlib.pyplot.axline 的示例#

无限线条

无限线条

安斯库姆四重奏

安斯库姆四重奏