Python中的 Matplotlib.axes.Axes.spy()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.spy()函数
matplotlib 库的 axes 模块中的Axes.spy()函数也用于绘制二维数组的稀疏模式。它还用于可视化数组的非零值。
Syntax: Axes.spy(self, Z, precision=0, marker=None, markersize=None, aspect=’equal’, origin=’upper’, **kwargs
Parameters: This method accept the following parameters that are described below:
- Z : This parameter is the array which is to be plotted.
- precision : This parameter is used to determine whether any non-zero value is to be plotted or not.
- origin : This parameter place the [0, 0] index of the array in the upper left or lower left corner of the axes.
- aspect : This parameter is an optional and it is used to control the aspect ratio of the axes.
Returns: This returns the following:
- ret:This returns the AxesImage or Line2D. And it depend on style of plotting
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.spy()函数:
示例 1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
fig, ax1 = plt.subplots()
x = np.random.randn(20, 50)
x[12, :] = 0.
x[:, 22] = 0.
ax1.spy(x)
plt.show()
ax1.set_title('matplotlib.axes.Axes.spy() Example')
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
fig, [(ax1, ax2), (ax3, ax4)] = plt.subplots(2, 2)
x = np.random.randn(20, 50)
x[5, :] = 0.
x[:, 12] = 0.
ax1.spy(x, markersize = 4)
ax2.spy(x, precision = 0.2, markersize = 4)
ax3.spy(x)
ax4.spy(x, precision = 0.4)
plt.show()
ax1.set_title('matplotlib.axes.Axes.spy() Example')
plt.show()
输出: