1"""
2=========
3Spy Demos
4=========
5
6Plot the sparsity pattern of arrays.
7"""
8
9import matplotlib.pyplot as plt
10import numpy as np
11
12
13# Fixing random state for reproducibility
14np.random.seed(19680801)
15
16fig, axs = plt.subplots(2, 2)
17ax1 = axs[0, 0]
18ax2 = axs[0, 1]
19ax3 = axs[1, 0]
20ax4 = axs[1, 1]
21
22x = np.random.randn(20, 20)
23x[5, :] = 0.
24x[:, 12] = 0.
25
26ax1.spy(x, markersize=5)
27ax2.spy(x, precision=0.1, markersize=5)
28
29ax3.spy(x)
30ax4.spy(x, precision=0.1)
31
32plt.show()
33
34#############################################################################
35#
36# .. admonition:: References
37#
38#    The use of the following functions, methods, classes and modules is shown
39#    in this example:
40#
41#    - `matplotlib.axes.Axes.spy` / `matplotlib.pyplot.spy`
42