I was trying to debug some visualization code and when I worked back to ultra-basics, I discovered a confusing behavior that makes me think I'm missing something fundamentally about matplotlib cmaps.
This works as i expect -- printing a range of reds and blues corresponding to randomly generated values between 0,1.
fig = plt.figure()
CMAP = "seismic" # blue-white-red colormap
a = np.array(np.random.rand(50,50)/2,).reshape(50,50)
plt.imshow(a, cmap=plt.get_cmap(CMAP))
But if I make the array values homogenous, the plot is always the same dark blue value regardless of what the array's value is.
fig = plt.figure()
CMAP = "seismic" # blue-white-red colormap
#either of these two lines gives the same result
a = np.array([0.9]*50*50).reshape(50,50)
a = np.array([0.1]*50*50).reshape(50,50)
As long as the array doesn't have homogenous values, it seems to work as expected, for example
a = np.array([0.1,.9]*25*50).reshape(50,50)
renders with stripes, as I'd guess.




