matplotlib.axes.Axes.grid#

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

配置网格线。

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

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

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

哪个{'major', 'minor', 'both'}, 可选

要应用更改的网格线。

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

布尔值

标签

对象

线型 或 ls

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

linewidth 或 lw

float

标记

标记样式字符串,PathMarkerStyle

markeredgecolor 或 mec

color

markeredgewidth 或 mew

float

markerfacecolor 或 mfc

color

markerfacecoloralt 或 mfcalt

color

markersize 或 ms

float

markevery

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

鼠标悬停

布尔值

path_effects

AbstractPathEffect 的列表

选择器

浮点数或可调用对象[[Artist, Event], 元组[bool, dict]]

pickradius

float

光栅化

布尔值

sketch_params

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

snap

布尔值或无

solid_capstyle

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

solid_joinstyle

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

transform

未知

url

str

visible

布尔值

xdata

一维数组

ydata

一维数组

zorder

float

注释

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

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

断开的条形图

Broken Barh

交叉谱密度 (CSD)

Cross spectral density (CSD)

fill_between 带透明度

fill_between with transparency

功率谱密度 (PSD)

Power spectral density (PSD)

散点图演示2

Scatter Demo2

带有图例的散点图

Scatter plot with a legend

线图

Line plot

交叉相关和自相关

Cross- and auto-correlation

轮廓角掩码

Contour corner mask

带注释的热图

Annotated heatmap

多种绘制图像的方法

Many ways to plot images

水印图片

Watermark image

Axes 属性

Axes properties

倒置轴

Inverted axis

累积分布

Cumulative distributions

极坐标图

Polar plot

日期刻度标签

Date tick labels

多行

Multiline

文本水印

Text watermark

PathPatch 对象

PathPatch object

轴方向演示

axis_direction demo

floating_axes 功能

floating_axes features

图的结构

Anatomy of a figure

32年间的股票价格

Stock prices over 32 years

衰变

Decay

双摆问题

The double pendulum problem

自定义投影

Custom projection

路径效果演示

Patheffect Demo

同一图中的2D和3D轴

2D and 3D Axes in same figure

Asinh 演示

Asinh Demo

日志演示

Log Demo

刻度

Scales

对数轴

Log Axis

Symlog 演示

Symlog Demo

艺术家测试

Artist tests

快速入门指南

Quick start guide

轴刻度

Axis scales

轴刻度

Axis ticks