.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/misc/multiplot_animation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_misc_multiplot_animation.py: Multi-Subplot Image Update ========================== Example showing updating a multiple subplots with new random 512x512 data. .. GENERATED FROM PYTHON SOURCE LINES 7-48 .. image-sg:: /_gallery/misc/images/sphx_glr_multiplot_animation_001.webp :alt: multiplot animation :srcset: /_gallery/misc/images/sphx_glr_multiplot_animation_001.webp :class: sphx-glr-single-img .. code-block:: Python # test_example = false 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.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 10.242 seconds) .. _sphx_glr_download__gallery_misc_multiplot_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: multiplot_animation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: multiplot_animation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: multiplot_animation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_