matplotlib.pyplot.axhline#

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

添加一条横跨整个或部分 Axes 的水平线。

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

参数:
yfloat, 默认值: 0

y 位置在 数据坐标 中。

xminfloat, 默认值: 0

坐标系 中的起始 x 位置。应在 0 和 1 之间,0 表示图的最左边,1 表示图的最右边。

xmaxfloat, 默认值: 1

坐标系 中的结束 x 位置。应在 0 和 1 之间,0 表示图的最左边,1 表示图的最右边。

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

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

属性

描述

agg_filter

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

alpha

标量或无

animated

布尔

抗锯齿 或 aa

布尔

clip_box

BboxBase 或 None

clip_on

布尔

clip_path

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

颜色 或 c

color

dash_capstyle

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

dash_joinstyle

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

dashes

浮点数序列(开/关墨水以点为单位)或 (None, None)

数据

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

drawstyle 或 ds

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

figure

FigureSubFigure

fillstyle

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

gapcolor

color or None

gid

str

in_layout

布尔

标签

对象

linestyle 或 ls

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

linewidth 或 lw

浮动

标记

标记样式字符串,PathMarkerStyle

markeredgecolor 或 mec

color

markeredgewidth 或 mew

浮动

markerfacecolor 或 mfc

color

markerfacecoloralt 或 mfcalt

color

markersize 或 ms

浮动

markevery

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

鼠标悬停

布尔

path_effects

AbstractPathEffect 列表

picker

float 或 callable[[Artist, Event], tuple[bool, dict]]

pickradius

浮动

光栅化

布尔

sketch_params

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

snap

布尔值或无

solid_capstyle

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

solid_joinstyle

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

transform

未知

url

str

可见

布尔

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 的示例#

默认属性循环中的颜色

Colors in the default property cycle

无限行

Infinite lines

Zorder 演示

Zorder Demo