Reputation: 119
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
images = []
c=0
a=0
b=0
while a < 31:
mat0 = np.zeros((100, 100))
i=0
while i < 3:
k = 0
while k < 3:
mat0[a+i, a+k+c] = 1+b
k += 1
i+=1
images.append(mat0)
a+=1
c+=1
b+=1
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.matshow(images[2], cmap=plt.cm.Blues)
I'd like to color each non-zero enter of the matrix with a different shade of blue for each matrix. For example images[0] contains a block of 1 that I want color with a light blue, images[1] contains a block of "2" that I want to color with a darker blue, and so on. How can I do this? Thanks!
Upvotes: 4
Views: 102
Reputation: 3013
Try the following, by also setting accordingly vmin
and vmax
kwargs:
fig, ax = plt.subplots()
for image in images:
ax.cla()
ax.imshow(image, cmap=plt.cm.Blues, vmin=1, vmax=31)
plt.pause(0.1)
which gives:
Upvotes: 2