.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/image/image_reshaping.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_image_image_reshaping.py: Image reshaping =============== An example that shows replacement of the image data with new data of a different shape. Under the hood, this creates a new buffer and a new array of Textures on the GPU that replace the older Textures. Creating a new buffer and textures has a performance cost, so you should do this only if you need to or if the performance drawback is not a concern for your use case. Note that the vmin-vmax is reset when you replace the buffers. .. GENERATED FROM PYTHON SOURCE LINES 12-50 .. image-sg:: /_gallery/image/images/sphx_glr_image_reshaping_001.webp :alt: image reshaping :srcset: /_gallery/image/images/sphx_glr_image_reshaping_001.webp :class: sphx-glr-single-img .. code-block:: Python # test_example = false import numpy as np import fastplotlib as fpl # create some data, diagonal sinusoidal bands xs = np.linspace(0, 2300, 2300, dtype=np.float16) full_data = np.vstack([np.cos(np.sqrt(xs + (np.pi / 2) * i)) * i for i in range(2_300)]) figure = fpl.Figure() image = figure[0, 0].add_image(full_data) figure.show() i, j = 1, 1 def update(): global i, j # set the new image data as a subset of the full data row = np.abs(np.sin(i)) * 2300 col = np.abs(np.cos(i)) * 2300 image.data = full_data[: int(row), : int(col)] i += 0.01 j += 0.01 figure.add_animations(update) # NOTE: fpl.loop.run() should not be used for interactive sessions # See the "JupyterLab and IPython" section in the user guide if __name__ == "__main__": print(__doc__) fpl.loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.590 seconds) .. _sphx_glr_download__gallery_image_image_reshaping.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: image_reshaping.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: image_reshaping.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_