matplotlib.axes.Axes.axvline#

Axes.axvline(x=0, ymin=0, ymax=1, **kwargs)[source]#

添加一条垂直线,跨越整个或部分坐标轴。

注意:如果想在数据坐标中设置Y轴限制,请改用vlines

参数:
xfloat, default: 0

数据坐标中的x位置。

yminfloat, default: 0

坐标轴坐标中的起始y位置。应在0到1之间,0表示绘图底部,1表示绘图顶部。

ymaxfloat, default: 1

坐标轴坐标中的结束y位置。应在0到1之间,0表示绘图底部,1表示绘图顶部。

返回:
Line2D

通过两个点(x, ymin)(x, ymax)指定的Line2D对象。其变换设置使得x数据坐标中,而y坐标轴坐标中。

这仍然是一条通用线,其垂直特性仅通过为两个点使用相同的x值来实现。因此,如果以后想更改x值,必须提供两个值,例如line.set_xdata([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

浮点数

另请参阅

vlines

在数据坐标中添加垂直线。

axvspan

在坐标轴上添加垂直范围(矩形)。

axline

添加任意斜率的线。

示例

  • x = 0处绘制一条跨越Y轴范围的粗红色垂直线

    >>> axvline(linewidth=4, color='r')
    
  • x = 1处绘制一条跨越Y轴范围的默认垂直线

    >>> axvline(x=1)
    
  • x = .5处绘制一条跨越Y轴中间一半范围的默认垂直线

    >>> axvline(x=.5, ymin=0.25, ymax=0.75)
    

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

十字光标

十字光标

无限线条

无限线条

SkewT-logP 图:使用变换和自定义投影

SkewT-logP 图:使用变换和自定义投影

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

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

绘制跨越坐标轴的区域

绘制跨越坐标轴的区域

次坐标轴

次坐标轴

Usetex 文本基线

Usetex 文本基线

绘图的生命周期

绘图的生命周期

注解

注解