When creating an numpy
array with dtype=float
, the the presentation method using matplotlib.pyplot.imshow
appears to be dependent on the v
Found out that imshow
does normalize by default, so to avoid this, the vmin
and vmax
must be given to imshow
, which is then:
plt.imshow(img, cmap='gray', vmin=0, vmax=1)
You have to fix the limits of the color-scale:
plt.imshow(img, cmap='gray',clim=(0,1))
To get a good feeling of what is going on you could include a colorbar which visualizes the conversion between colors and numerical values; for example using the following code:
fig,ax = plt.subplots()
cax = plt.imshow(img, cmap='gray')
cbar = fig.colorbar(cax)
plt.show()
Doing this for the two examples immediately makes clear that matplotlib.pyplot updates the range of the color-scale to the data. Consequently the conversion betweens colors and numerical values is different for the two cases.