I want to generate a 2-d
figure with a (fixed) color scale that does not vary with the range of
the data being plotted.
How do I do this? Attempts to specify vimin and vmax appear to be
ignored.
The following example:
#
import numpy
data = numpy.zeros(shape=(240,240),dtype=int)
data[ 0: 80] = -1
data[ 80:160] = 0
data[160:] = 1
import matplotlib.pyplot as plot
figure = plot.figure()
ax = figure.add_subplot(111)
cax = ax.imshow(data, interpolation=‘bilinear’)
ax.set_title(‘test data with fixed colorbar’)
colorbar = figure.colorbar(cax, ticks=[-1, 0, 1])
colorbar.ax.set_yticklabels([’-1’, ‘0’, ‘1’])
plot.show()
#
produces a figure with 3
color bands (blue,green,red) and matching color bar with labels
(-1,0,1) as expected.
if the data[160:]=1 specification is deleted, in the above code, the
resulting figure has 2 color bands (blue,red) and the associated color
bar is identical to the original, but the labels are (-1,0).
What I want, in this second case, is a blue-green figure and a color
bar with labels identical to the original example.
– jv