.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/window_layouts/rect_frac_layout.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_window_layouts_rect_frac_layout.py: Rect Fractional Layout ====================== Create subplots using rects given as fractions of the canvas. This example plots two images and their histograms in separate subplots .. GENERATED FROM PYTHON SOURCE LINES 9-74 .. image-sg:: /_gallery/window_layouts/images/sphx_glr_rect_frac_layout_001.webp :alt: rect frac layout :srcset: /_gallery/window_layouts/images/sphx_glr_rect_frac_layout_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 float64 array to float32 warn(f"casting {array.dtype} array to float32") | .. code-block:: Python # test_example = true import numpy as np import imageio.v3 as iio import fastplotlib as fpl # load images img1 = iio.imread("imageio:astronaut.png") img2 = iio.imread("imageio:wikkie.png") # calculate histograms hist_1, edges_1 = np.histogram(img1) centers_1 = edges_1[:-1] + np.diff(edges_1) / 2 hist_2, edges_2 = np.histogram(img2) centers_2 = edges_2[:-1] + np.diff(edges_2) / 2 # figure size in pixels size = (700, 560) # rect is (x, y, width, height) # here it is defined as fractions of the canvas rects = [ (0, 0, 0.3, 0.5), # for image1 (0, 0.5, 0.3, 0.5), # for image2 (0.3, 0, 0.7, 0.5), # for image1 histogram (0.3, 0.5, 0.7, 0.5), # for image2 histogram ] # create a figure using the rects and size # also give each subplot a name figure = fpl.Figure( rects=rects, names=["astronaut image", "wikkie image", "astronaut histogram", "wikkie histogram"], size=size ) # add image to the corresponding subplots figure["astronaut image"].add_image(img1) figure["wikkie image"].add_image(img2) # add histogram to the corresponding subplots figure["astronaut histogram"].add_line(np.column_stack([centers_1, hist_1])) figure["wikkie histogram"].add_line(np.column_stack([centers_2, hist_2])) for subplot in figure: if "image" in subplot.name: # remove axes from image subplots to reduce clutter subplot.axes.visible = False continue # don't maintain aspect ratio for the histogram subplots subplot.camera.maintain_aspect = False 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() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.803 seconds) .. _sphx_glr_download__gallery_window_layouts_rect_frac_layout.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: rect_frac_layout.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: rect_frac_layout.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: rect_frac_layout.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_