matplotlib.pyplot.spy#

matplotlib.pyplot.spy(Z, *, precision=0, marker=None, markersize=None, aspect='equal', origin='upper', **kwargs)[source]#

绘制 2D 数组的稀疏模式。

可视化数组的非零值。

提供两种绘图样式:图像(image)和标记(marker)。两者均可用于完整数组,但仅标记样式适用于 scipy.sparse.spmatrix 实例。

图像样式

如果 marker 和 markersize 为 None,则使用 imshow。任何额外剩余的关键字参数都将传递给此方法。

标记样式

如果 Z 是 scipy.sparse.spmatrix,或者 marker 或 markersize 不为 None,则会返回一个 Line2D 对象,其中 marker 的值决定了标记类型,任何剩余的关键字参数将传递给 plot。

参数:
Z(M, N) 数组类型

要绘制的数组。

precisionfloat 或 'present',默认值:0

如果 precision 为 0,则绘制所有非零值。否则,将绘制满足 \(|Z| > precision\) 的值。

对于 scipy.sparse.spmatrix 实例,还可以传递 'present'。在这种情况下,数组中存在的任何值都将被绘制,即使其值严格为零。

aspect{'equal', 'auto', None} 或 float,默认值:'equal'

Axes 的纵横比。此参数对于图像尤为重要,因为它决定了数据像素是否为正方形。

此参数是显式调用 Axes.set_aspect 的快捷方式。详情请参考该函数。

  • 'equal':确保纵横比为 1。像素将为正方形。

  • 'auto':Axes 保持固定,纵横比会调整,以便数据适合 Axes。通常,这将导致非正方形像素。

  • None:使用 rcParams["image.aspect"](默认值:'equal')。

origin{'upper', 'lower'},默认:rcParams["image.origin"](默认值:'upper')

将数组的 [0, 0] 索引放在 Axes 的左上角或左下角。'upper' 约定通常用于矩阵和图像。

返回:
AxesImage 或 Line2D

返回类型取决于绘图样式(见上文)。

其他参数:
**kwargs

支持的附加参数取决于绘图样式。

对于图像样式,可以传递 imshow 的以下附加参数:

对于标记样式,可以传递除 linestyle 之外的任何 Line2D 属性

属性

描述

agg_filter

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

alpha

浮点数或 None

animated

布尔值

antialiased 或 aa

布尔值

clip_box

BboxBase 或 None

clip_on

布尔值

clip_path

Patch 或 (Path, Transform) 或 None

color 或 c

color

dash_capstyle

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

dash_joinstyle

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

dashes

浮点数序列(点中的开/关墨迹)或 (None, None)

data

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

drawstyle 或 ds

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

figure

Figure 或 SubFigure

fillstyle

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

gapcolor

颜色 或 None

gid

str

in_layout

布尔值

label

object

linestyle 或 ls

{'-', '--', '-.', ':', '', ...} 或 (offset, on-off-seq)

linewidth 或 lw

浮点数

marker

标记样式字符串、Path 或 MarkerStyle

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]

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

浮点数

备注

注意

这是 pyplot 包装器,对应于 axes.Axes.spy。

使用 matplotlib.pyplot.spy 的示例#

Spy 演示

Spy 演示