.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/spaces_transforms/scaling_image.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_spaces_transforms_scaling_image.py: Scale image =========== This examples illustrates the various spaces that you may need to map between, plots an image to show these mappings. .. GENERATED FROM PYTHON SOURCE LINES 8-94 .. image-sg:: /_gallery/spaces_transforms/images/sphx_glr_scaling_image_001.webp :alt: scaling image :srcset: /_gallery/spaces_transforms/images/sphx_glr_scaling_image_001.webp :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/fastplotlib/fastplotlib/fastplotlib/graphics/features/_base.py:18: UserWarning: casting int64 array to float32 warn(f"casting {array.dtype} array to float32") | .. code-block:: Python # test_example = true import numpy as np import fastplotlib as fpl figure = fpl.Figure(size=(700, 560)) # an image to demonstrate some data in model/data space image_data = np.array( [ [0, 1, 2], [3, 4, 5], [5, 6, 7], [8, 9, 10], ] ) image = figure[0, 0].add_image(image_data, cmap="turbo") # a scatter that will be in the same space as the image # used to indicates a few points on the image scatter_data = np.array([[0, 1], [2, 3]]) scatter = figure[0, 0].add_scatter( scatter_data, sizes=15, colors=["blue", "red"], edge_colors="w", edge_width=2.0, ) # text to indicate the scatter point positions in all spaces text_0 = figure[0, 0].add_text( text="", anchor="bottom-left", face_color="w", outline_color="k", outline_thickness=0.5, ) text_1 = figure[0, 0].add_text( text="", anchor="bottom-left", face_color="w", outline_color="k", outline_thickness=0.5, ) scaling = (2, 0.5, 1.0) # scale (x, y, z) image.scale = scaling scatter.scale = scaling def update_text(): # get the position of the scatter points in world space # graphics can map from model <-> world space point_0_world = scatter.map_model_to_world(scatter.data[0]) point_1_world = scatter.map_model_to_world(scatter.data[1]) # text is always just set in world space text_0.offset = point_0_world text_1.offset = point_1_world # use subplot to map to world <-> screen space point_0_screen = figure[0, 0].map_world_to_screen(point_0_world) point_1_screen = figure[0, 0].map_world_to_screen(point_1_world) # set text to display model, world and screen space position of the 2 points text_0.text = ( f"model pos: [{', '.join(str(round(p, 2)) for p in scatter.data[0])}]\n" f"world pos: [{', '.join(str(round(p, 2)) for p in point_0_world)}]\n" f"screen pos: [{', '.join(str(round(p)) for p in point_0_screen)}]" ) text_1.text = ( f"model pos: [{', '.join(str(round(p, 2)) for p in scatter.data[1])}]\n" f"world pos: [{', '.join(str(round(p, 2)) for p in point_1_world)}]\n" f"screen pos: [{', '.join(str(round(p)) for p in point_1_screen)}]" ) figure.add_animations(update_text) figure.show() fpl.loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.450 seconds) .. _sphx_glr_download__gallery_spaces_transforms_scaling_image.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: scaling_image.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: scaling_image.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_