matplotlib.pyplot.axhline#

matplotlib.pyplot.axhline(y=0, xmin=0, xmax=1, **kwargs)[源码]#

添加一条水平线,跨越 Axes 的全部或部分。

注意:如果您想使用数据坐标设置 x 轴限制,请改用 hlines

参数:
yfloat, 默认值: 0

数据坐标中的 y 位置。

xmin浮点数,默认值:0

轴坐标中的起始 x 位置。应在 0 到 1 之间,0 为绘图的最左侧,1 为绘图的最右侧。

xmax浮点数,默认值:1

轴坐标中的结束 x 位置。应在 0 到 1 之间,0 为绘图的最左侧,1 为绘图的最右侧。

返回:
Line2D

一个由两个点 (xmin, y)(xmax, y) 指定的 Line2D。其变换设置使得 x 处于 轴坐标,而 y 处于 数据坐标

这仍然是一条通用直线,“水平”特性仅通过对两个点使用相同的 y 值来实现。因此,如果您以后想更改 y 值,则必须提供两个值 line.set_ydata([3, 3])

其他参数:
**kwargs

有效的关键字参数是 Line2D 属性,'transform' 除外。

属性

描述

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

标记样式字符串、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

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

浮点数

另请参阅

hlines

在数据坐标中添加水平线。

axhspan

在整个轴上添加一个水平跨度(矩形)。

axline

添加任意斜率的线。

备注

注意

这是 axes.Axes.axhlinepyplot 封装

示例

  • 在 'y' = 0 处绘制一条跨越整个 x 范围的粗红色水平线

    >>> axhline(linewidth=4, color='r')
    
  • 在 'y' = 1 处绘制一条跨越整个 x 范围的默认水平线

    >>> axhline(y=1)
    
  • 在 'y' = .5 处绘制一条跨越 x 范围中间一半的默认水平线

    >>> axhline(y=.5, xmin=0.25, xmax=0.75)
    

使用 matplotlib.pyplot.axhline 的示例#

无限线条

无限线条

Zorder 演示

Zorder 演示