Scaled Colorization
Scaled colorization divides the data range into a discrete number of evenly spaced bins which are then used to look up the corresponding color from a color map. The following example uses the Gouldian color map to colorize the peaks example data:
Corresponding Python code:
1peaks = viren2d.peaks()
2canvas_width = 500
3cmap_bins = [256, 16, 8]
4column_width = (canvas_width - (len(cmap_bins) * 10)) / len(cmap_bins)
5scale = column_width / peaks.width
6
7canvas_height = int(scale * peaks.height + 10.5)
8painter = viren2d.Painter(
9 width=canvas_width, height=canvas_height, color='white!0')
10
11text_style = viren2d.TextStyle(family='xkcd', size=18, color='black')
12
13x = column_width / 2 + 5
14for bins in cmap_bins:
15 vis = viren2d.colorize_scaled(
16 data=peaks, colormap='gouldian', low=-6.5, high=8, bins=bins)
17
18 painter.draw_image(
19 image=vis, position=(x, canvas_height / 2), anchor='center',
20 scale_x=scale, scale_y=scale, rotation=0, clip_factor=0.2)
21
22 painter.draw_text(
23 text=[f'{bins} Bins'], anchor='bottom-left', rotation=-90,
24 position=(x + column_width / 2 - 5, canvas_height * 0.85),
25 text_style=text_style)
26
27 x += column_width + 10
