-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathmultiplot_animation.py
More file actions
48 lines (37 loc) · 1.36 KB
/
multiplot_animation.py
File metadata and controls
48 lines (37 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Multi-Subplot Image Update
==========================
Example showing updating a multiple subplots with new random 512x512 data.
"""
# test_example = false
# sphinx_gallery_pygfx_docs = 'animate'
import fastplotlib as fpl
import numpy as np
# Figure of shape 2 x 3 with all controllers synced
figure = fpl.Figure(shape=(2, 3), controller_ids="sync", size=(700, 560))
# Make a random image graphic for each subplot
for subplot in figure:
# create image data
data = np.random.rand(512, 512)
# add an image to the subplot
subplot.add_image(data, name="rand-img")
figure[0,1]["rand-img"].cmap = "viridis"
figure[1,0]["rand-img"].cmap = "Wistia"
figure[0,2]["rand-img"].cmap = "gray"
figure[1,1]["rand-img"].cmap = "spring"
# Define a function to update the image graphics with new data
# add_animations will pass the gridplot to the animation function
def update_data(f):
for subplot in f:
new_data = np.random.rand(512, 512)
# index the image graphic by name and set the data
subplot["rand-img"].data = new_data
# add the animation function
figure.add_animations(update_data)
# show the gridplot
figure.show()
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
# please see our docs for using fastplotlib interactively in ipython and jupyter
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()