.. 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_image_antialiasing.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_image_antialiasing.f90: Image resampling ================ An image with more pixels than the figure has to show them must be downsampled. Drawn with ``interpolation="nearest"`` each screen pixel simply picks one source pixel, which turns fine structure into moire patterns. ``interpolation="bilinear"`` averages neighbouring pixels instead. This follows matplotlib's `image antialiasing `_. fplotlib has two interpolation modes, ``"nearest"`` and ``"bilinear"``; matplotlib's other filters (``"hanning"``, ``"lanczos"``, ...) are not available. .. GENERATED FROM PYTHON SOURCE LINES 14-23 .. code-block:: Fortran program plot_image_antialiasing use fplotlib, only: dp, figure, imshow, savefig, subplot, title implicit none integer, parameter :: n = 600 real(dp), parameter :: pi = 3.14159265358979323846_dp real(dp), allocatable :: a(:, :) real(dp) :: x, y integer :: i, j .. GENERATED FROM PYTHON SOURCE LINES 24-27 A chirp, :math:`a(x, y) = \sin\left(2\pi \cdot 60\,(x^2 + y^2)\right)` on the unit square: the spatial frequency grows with the distance from the corner, so somewhere the pattern is finer than the screen can resolve. .. GENERATED FROM PYTHON SOURCE LINES 29-37 .. code-block:: Fortran :dedent: 1 allocate (a(n, n)) do j = 1, n do i = 1, n x = real(j - 1, dp)/real(n - 1, dp) y = real(i - 1, dp)/real(n - 1, dp) a(i, j) = sin(2.0_dp*pi*60.0_dp*(x**2 + y**2)) end do end do .. GENERATED FROM PYTHON SOURCE LINES 38-41 The same array twice. The left panel shows the moire rings of nearest neighbour sampling; the right one averages neighbouring pixels, so the fine structure is blurred rather than dropped and the spurious pattern changes. .. GENERATED FROM PYTHON SOURCE LINES 42-56 .. code-block:: Fortran call figure(figsize=[10.0_dp, 5.0_dp]) call subplot(1, 2, 1) call imshow(a, cmap="RdBu", interpolation="nearest") call title("interpolation = nearest") call subplot(1, 2, 2) call imshow(a, cmap="RdBu", interpolation="bilinear") call title("interpolation = bilinear") call savefig("image_antialiasing.png") print *, "wrote image_antialiasing.png" end program plot_image_antialiasing .. image-sg:: /auto_gallery/images_contours_and_fields/images/sphx_glr_plot_image_antialiasing_001.png :alt: plot image antialiasing :srcset: /auto_gallery/images_contours_and_fields/images/sphx_glr_plot_image_antialiasing_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote image_antialiasing.png .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.450 seconds) .. _sphx_glr_download_auto_gallery_images_contours_and_fields_plot_image_antialiasing.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_image_antialiasing.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_image_antialiasing.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_