python - Assign Specific Values to Matplotlib graph -
i have 2 values in numpy array. 0,1. want ensure 1 black , 0 grey when graph array.
how can in matplotlib?
thank you
assuming want plot image plot (plt.imshow()
), can select colormap "gray_r" has white lowest , black highest color, gray in middle. if normalize image plot values between -1 , 1, array's 0 value correspond middle of colormap (being gray) , 1 correspond upper end of colormap (being black).
import matplotlib.pyplot plt import numpy np; np.random.seed(0) = np.random.randint(0,2, size=(12,25)) plt.imshow(a, cmap="gray_r", vmin=-1, vmax=1) plt.show()
Comments
Post a Comment