python - matplotlib colourbar custom colour 1 value -
i want normal colorbar differences in color specific value.
my data covers range (0,1) want pass values outside range (because errors), , want see them color outside main range.
so want assign color black -1 values , normal colorbar in range of (0,1). possible?
yes don't need rebuild colormap specific case (which takes effort). can keep values aside using vmin , vmax limits data , specify color values below or on limits (using set_under , set_over).
check following example:
import matplotlib.pyplot plt import numpy np x, y = np.meshgrid(np.linspace(0, 10, 100), np.linspace(0, 10, 100)) im = (x**2 + y**2)/100-0.5 # creating synthetic data example p = plt.imshow(im.t, vmin=0, vmax=1, origin='lower', interpolation='nearest') # set limits vmin , vmax p.cmap.set_under('k') # set color under lower limit (k black) p.cmap.set_over('w') # set color on upper limit (w white) plt.show() , results in this:
everything below 0 black, on 1 white.
