def draw(self): svg = self.svg svg.empty() for i in xrange(self.ncolors): for j in xrange(self.ncolors): color = color_scale.color(color_scale.color64(i, j)) svg.rect("R_" + color, i * self.dx, j * self.dy, self.dx, self.dy, color) bary = self.palette_side + self.bar_region / 2 - self.bar_height / 2 dhistogram = self.display_histogram() maxcount = 1 if dhistogram: maxcount = float(max(dhistogram.values())) for i in xrange(self.palette_side): color_value = self.interpolation_value(i) color = self.scale.interpolate_color(color_value) adjustment = (dhistogram.get(i, 0) / maxcount) * self.histogram_region #print i, adjustment svg.rect("V" + color, i, bary, 1, adjustment + self.bar_height, color) circley = self.palette_side + self.bar_region / 2 m = self.scale.minvalue M = self.scale.maxvalue for (value, clr) in self.scale.breakpoints: color = color_scale.color(clr) circlex = (value - m)/(M - m) * self.palette_side name = "breakpoint_" + color self.add_circle(name, circlex, circley, color) svg.text(None, 0, 0, self.title, "black") svg.text(None, 0, bary, "%3.1f" % m, "black") atts = {"text-anchor": "end"} svg.text(None, self.palette_side, bary, "%3.1f" % M, "black", **atts) if m < 0 and M > 0: zvalue = self.display_value(0) svg.text(None, zvalue, bary, "0", "black") svg.send_commands()
def draw_heat_map(canvas, a, dx, dy): lowclr = clr(200, 255, 255) highclr = clr(255, 200, 0) maxval = numpy.max(a) minval = numpy.min(a) diff = maxval - minval if diff<0.1: return for i in xrange(len(a)): rowi = a[i] for j in xrange(len(rowi)): val = rowi[j] intensity = (val - minval)/diff iclr = (1-intensity)*lowclr + intensity*highclr canvas.rect(None, i*dx, j*dy, dx, dy, color(iclr)) canvas.send_commands()