matplotlib.axes.Axes.axhline#

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

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

注意:如果想在数据坐标中设置x轴范围,请使用 hlines 代替。

参数:
y浮点数, 默认值: 0

y轴位置,位于 数据坐标

xmin浮点数,默认值:0

起始x轴位置,位于 坐标轴坐标。应介于0和1之间,其中0表示绘图区域的最左侧,1表示最右侧。

xmax浮点数,默认值:1

结束x轴位置,位于 坐标轴坐标。应介于0和1之间,其中0表示绘图区域的最左侧,1表示最右侧。

返回:
Line2D

一个 Line2D 通过两个点 (xmin, y), (xmax, y) 指定。其变换设置使得 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

字符串

in_layout

布尔值

label

对象

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

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

字符串

visible

布尔值

xdata

一维数组

ydata

一维数组

zorder

浮点数

另请参阅

hlines

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

axhspan

在坐标轴上添加一个水平范围(矩形)。

axline

添加任意斜率的线。

示例

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

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

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

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

使用 matplotlib.axes.Axes.axhline 的示例#

十字光标

十字光标

无限线条

无限线条

填充两条线之间的区域

填充两条线之间的区域

使用 fill_between 填充由逻辑掩码定义的区域

使用 fill_between 填充由逻辑掩码定义的区域

带线条、日期和文本的时间线

带线条、日期和文本的时间线

绘制二维数据集的置信椭圆

绘制二维数据集的置信椭圆

双直方图

双直方图

多行

多行

Usetex 文本基线

Usetex 文本基线