Colour A Binary Matrix Matplotlib
highlightc = np.zeros([N, N]) print highlightc c = len(highlightc) colour = [0.21]*c colour = np.array(colour) print colour for x, y in hl: highlightc[x, y] = 1##set so binary
Solution 1:
ax.imshow(X)
adjusts the color scale so that the lowest value in X is mapped to the lowest color, and the highest value in X is mapped to the highest color in the cmap
.
When you multiply highlight
by a constant colour
, the highest value in X
drops from 1 to 0.21, but that has no effect on ax.imshow
since the color scale gets adjusted as well, thwarting your intention.
If, however, you supply vmin=0
, vmax=1
parameters, then ax.imshow
will not adjust the color range -- it will associate 0 with the lowest color and 1 with the highest:
import numpy as np
import matplotlib.pyplot as plt
N = 150
highlightc = np.zeros([N, N])
M = 1000
hl = np.random.randint(N, size=(M, 2))
highlightc[zip(*hl)] = 1
colour = 0.21
fig, ax = plt.subplots()
h = ax.imshow(
(highlightc * colour), interpolation='nearest', cmap=plt.cm.spectral_r,
vmin=0, vmax=1)
plt.show()
Post a Comment for "Colour A Binary Matrix Matplotlib"