matplotlib.pyplot.grid#

matplotlib.pyplot.grid(visible=None, which='major', axis='both', **kwargs)[source]#

配置网格线。

参数:
visible布尔值或None,可选

是否显示网格线。如果提供了任何 kwargs,则假定您希望开启网格,并且 visible 将设置为 True。

如果 visibleNone 且未提供 kwargs,则此项将切换线条的可见性。

which{'major', 'minor', 'both'},可选

要应用更改的网格线类型。

axis{'both', 'x', 'y'},可选

要应用更改的坐标轴。

**kwargsLine2D 属性

定义网格的线条属性,例如:

grid(color='r', linestyle='-', linewidth=2)

有效的关键字参数有:

属性

描述

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

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

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

字符串

visible

布尔值

xdata

一维数组

ydata

一维数组

zorder

浮点数

备注

注意

这是 pyplot 封装axes.Axes.grid

坐标轴是作为一个整体绘制的,因此绘制网格的有效zorder由每个坐标轴的zorder决定,而不是由组成网格的 Line2D 对象的zorder决定。因此,要设置网格的zorder,请使用 set_axisbelow,或者为了获得更多控制,调用每个坐标轴的 set_zorder 方法。

使用 matplotlib.pyplot.grid 的示例#

步进图演示

步进图演示

自定义 Rc

自定义 Rc

Findobj 演示

Findobj 演示

使用 pyplot 的文本和数学文本

使用 pyplot 的文本和数学文本

自定义刻度

自定义刻度

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

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

地理投影

地理投影

Pyplot 教程

Pyplot 教程