Skip to content

Commit 8be73a3

Browse files
authored
Merge pull request #15498 from timhoffm/doc-matshow
Simplify matshow example
2 parents 0a1e157 + 53bef1a commit 8be73a3

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

examples/images_contours_and_fields/matshow.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,15 @@
33
Matshow
44
=======
55
6-
Simple `~.axes.Axes.matshow` example.
6+
`~.axes.Axes.matshow` visualizes a 2D matrix or array as color-coded image.
77
"""
88
import matplotlib.pyplot as plt
99
import numpy as np
1010

11+
# a 2D array with linearly increasing values on the diagonal
12+
a = np.diag(range(15))
1113

12-
def samplemat(dims):
13-
"""Make a matrix with all zeros and increasing elements on the diagonal"""
14-
aa = np.zeros(dims)
15-
for i in range(min(dims)):
16-
aa[i, i] = i
17-
return aa
18-
19-
20-
# Display matrix
21-
plt.matshow(samplemat((15, 15)))
14+
plt.matshow(a)
2215

2316
plt.show()
2417

0 commit comments

Comments
 (0)