.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_gallery/images_contours_and_fields/plot_masked_image.f90" .. 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_auto_gallery_images_contours_and_fields_plot_masked_image.f90: Masked Image Display ==================== This example demonstrates how to display an image with masked regions, allowing you to hide or highlight certain areas of your data. This is useful for focusing on specific regions of interest or handling missing data values. The example creates a simple 2D array and displays it using :f:subr:`imshow` with masking capabilities. .. GENERATED FROM PYTHON SOURCE LINES 10-20 .. code-block:: Fortran program plot_masked_image use, intrinsic :: ieee_arithmetic, only: ieee_value, ieee_quiet_nan use fplotlib, only: colorbar, dp, figure, imshow, savefig, set_bad, title, xlabel, & ylabel implicit none integer, parameter :: nx = 50, ny = 50 real(dp) :: data(ny, nx), x(nx), y(ny) integer :: i, j real(dp), parameter :: pi = 3.14159265358979323846_dp .. GENERATED FROM PYTHON SOURCE LINES 21-22 Create a grid of x and y values .. GENERATED FROM PYTHON SOURCE LINES 24-31 .. code-block:: Fortran :dedent: 1 do i = 1, nx x(i) = -5.0_dp + 10.0_dp * real(i - 1, dp) / real(nx - 1, dp) end do do j = 1, ny y(j) = -5.0_dp + 10.0_dp * real(j - 1, dp) / real(ny - 1, dp) end do .. GENERATED FROM PYTHON SOURCE LINES 32-33 Create a 2D data field, the Gaussian :math:`f(x, y) = e^{-(x^2 + y^2)/2}` .. GENERATED FROM PYTHON SOURCE LINES 35-40 .. code-block:: Fortran :dedent: 1 do j = 1, ny do i = 1, nx data(j, i) = exp(-(x(i)**2 + y(j)**2) / 2.0_dp) end do end do .. GENERATED FROM PYTHON SOURCE LINES 41-43 Fortran has no masked arrays, so masked entries are NaN: fplotlib draws them with the "bad" colour. Here a circular region in the centre is masked out. .. GENERATED FROM PYTHON SOURCE LINES 45-52 .. code-block:: Fortran :dedent: 1 do j = 1, ny do i = 1, nx if (sqrt(x(i)**2 + y(j)**2) < 1.5_dp) then data(j, i) = ieee_value(1.0_dp, ieee_quiet_nan) end if end do end do .. GENERATED FROM PYTHON SOURCE LINES 53-55 Display the image with a colormap. The image shows the 2D data field with the center region masked out, creating a "hole" in the visualization. .. GENERATED FROM PYTHON SOURCE LINES 56-68 .. code-block:: Fortran call figure(figsize=[8.0_dp, 6.0_dp]) call set_bad("lightgray") call imshow(data, cmap="viridis") call title("Masked Image: 2D Gaussian with Center Masked") call xlabel("X index") call ylabel("Y index") call colorbar() call savefig("masked_image.png") print *, "wrote masked_image.png" end program plot_masked_image .. image-sg:: /auto_gallery/images_contours_and_fields/images/sphx_glr_plot_masked_image_001.png :alt: plot masked image :srcset: /auto_gallery/images_contours_and_fields/images/sphx_glr_plot_masked_image_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote masked_image.png .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.207 seconds) .. _sphx_glr_download_auto_gallery_images_contours_and_fields_plot_masked_image.f90: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Fortran source code: plot_masked_image.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_masked_image.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_