matplotlib.pyplot.grid#

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

配置网格线。

参数:
可见布尔值或无, 可选

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

如果 visibleNone 并且没有 kwargs,这将切换线条的可见性。

哪个{'主要', '次要', '两者'}, 可选

要应用更改的网格线。

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

要应用更改的轴。

**kwargs : Line2D 属性Line2D 属性

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

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

有效的关键字参数是:

属性

描述

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'}

虚线

浮点数序列(开/关墨水以点为单位)或 (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

浮动

注释

备注

这是 axes.Axes.gridpyplot 包装器

轴是以单位绘制的,因此绘制网格的有效 zorder 由每个轴的 zorder 决定,而不是由构成网格的 Line2D 对象的 zorder 决定。因此,要设置网格的 zorder,请使用 set_axisbelow,或者为了更精细的控制,调用每个轴的 set_zorder 方法。

使用 matplotlib.pyplot.grid 的示例#

步骤演示

Step Demo

地理投影

Geographic Projections

使用 pyplot 的文本和数学文本

Text and mathtext using pyplot

自定义 Rc

Customize Rc

Findobj 演示

Findobj Demo

自定义比例

Custom scale

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

SkewT-logP diagram: using transforms and custom projections

Pyplot 教程

Pyplot tutorial