Hi everybody.
grd_min, grd_max = grd.min(), grd.max()
trans = 255
palette = [(255, 0, 0, trans), (255, 92, 0, trans), (255, 255, 0, trans), (0, 255, 0, trans),
(0, 255, 255, trans), (0, 0, 255, trans), (255, 0, 255, trans)]
cm = pg.ColorMap(np.linspace(grd_min, grd_max, num=len(palette), endpoint=True), palette)
lut = cm.getLookupTable(grd_min, grd_max)
img.setImage(grd)
img.setRect(rect)
img.setLookupTable(lut)
where img is ImageItem.
I make GradientLegend manually:
# Gradient legend:
gl = pg.GradientLegend((10, 200), (10, 30))
gradient = QtGui.QLinearGradient()
for pos, color in zip(*cm.getStops(1)):
gradient.setColorAt((pos-grd_min)/(grd_max - grd_min), QtGui.QColor(*color))
gl.setGradient(gradient)
pi.vb.addItem(gl)
#gl.scale(1, -1)
gl.setLabels({'asdhffdfdfh': 1625.0})
I think, this is ugly. And here is a problem: labels isn't shown.
I suspect, this is because of problem with coordinates. Both variants - with gl.scale and without it.
Is there any way to create GradientLegend without such large code? I think, this is typical task.