Colorbar In Information¶
This demo presents the colorbar in information scene in 2D and shows how the animation state evolves over time with lib-anim. The script defines a canva, adds the corresponding items, and updates them frame by frame to produce the final motion.

Full Code¶
1'''
22D colorbar array demo
3'''
4
5import numpy as np
6import anim
7
8# ═══ 2D Animation canva ═══════════════════════════════════════════════════
9
10class Canva(anim.plane.canva):
11
12 # ────────────────────────────────────────────────────────────────────────
13 def __init__(self, window, cmap):
14
15 # Number of pixels in the image
16 self.npix = 500
17
18 # Colormap
19 self.cmap = cmap
20
21 super().__init__(window,
22 display_boundaries = False,
23 pixelperunit = self.npix)
24
25 # ─── display
26
27 self.item.img = anim.plane.image(
28 position = [0.5, 0.5],
29 dimension = [1, 1],
30 array = self.phase(0),
31 colormap = self.cmap
32 )
33
34 # ────────────────────────────────────────────────────────────────────────
35 def phase(self, t):
36
37 # Base field
38 x = np.linspace(-0.5, 0.5, self.npix)
39 X, Y = np.meshgrid(x, x)
40 return np.angle(np.exp(t/(X + 1j*Y)/10))/np.pi
41
42 # ────────────────────────────────────────────────────────────────────────
43 def update(self, t):
44
45 self.item.img.array = self.phase(t.step)
46
47 # Confirm update
48 super().update(t)
49
50# ═══ Main ═════════════════════════════════════════════════════════════════
51
52W = anim.window('Colorbar animation')
53
54# colormap
55cmap = anim.colormap('turbo', range=[-1, 1])
56
57# ─── Information panel
58
59W.information.display(True)
60
61# This may be useful to setup the information canva dimensions
62# W.information.canva.display_boundaries = True
63
64# Set boundaries size
65W.information.canva.boundaries = [[0,1],[0,3]]
66
67W.information.canva.item.cbar = anim.plane.colorbar(
68 position = [0.8, 1],
69 dimension = [0.2, 2],
70 colormap = cmap,
71 ticks_number = 5,
72 ticks_fontsize = 0.1,
73 ticks_color = '#AAA'
74)
75
76# Add animation
77W.add(Canva, cmap=cmap)
78
79# Allow backward animation
80W.allow_backward = True
81W.allow_negative_time = True
82
83W.show()