.. 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_quiver_simple_demo.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_quiver_simple_demo.f90: Quiver simple demo ================== A vector field drawn as arrows, with a key that says how long an arrow of a given size is. This is matplotlib's `quiver simple demo `_, line for line. The grid comes from the Fortran standard library, much as the Python version gets it from numpy: ``stdlib_math`` has both ``arange`` and ``meshgrid``. To build this example on its own, add ``stdlib = "*"`` to the ``[dependencies]`` of your ``fpm.toml``. .. GENERATED FROM PYTHON SOURCE LINES 13-19 .. code-block:: Fortran program plot_quiver_simple_demo use fplotlib, only: dp, quiver, quiverkey, savefig use stdlib_math, only: arange, meshgrid implicit none real(dp), allocatable :: x(:), y(:), u(:, :), v(:, :) .. GENERATED FROM PYTHON SOURCE LINES 20-23 ``arange`` includes its end point, so the numpy ``arange(-10, 10, 1)`` is ``arange(-10, 9, 1)`` here. ``meshgrid`` uses numpy's default "xy" indexing: ``u(i, j)`` is ``x(j)`` and ``v(i, j)`` is ``y(i)``. .. GENERATED FROM PYTHON SOURCE LINES 25-29 .. code-block:: Fortran :dedent: 1 x = arange(-10.0_dp, 9.0_dp, 1.0_dp) y = arange(-10.0_dp, 9.0_dp, 1.0_dp) allocate (u(size(y), size(x)), v(size(y), size(x))) call meshgrid(x, y, u, v) .. GENERATED FROM PYTHON SOURCE LINES 30-38 :f:subr:`quiver` takes one entry per arrow, so the grid is flattened. The positions and the vectors are the same arrays: each arrow points away from the origin, and is the longer the farther out it sits. :f:subr:`quiverkey` adds a reference arrow of length 10, drawn to the same scale as the field. Its position is in axes coordinates, so ``y = 1.1`` puts it just above the plot; with ``labelpos="E"`` the arrow's head sits at that point and the label runs to its right. .. GENERATED FROM PYTHON SOURCE LINES 39-47 .. code-block:: Fortran call quiver(reshape(u, [size(u)]), reshape(v, [size(v)]), & reshape(u, [size(u)]), reshape(v, [size(v)])) call quiverkey(0.3_dp, 1.1_dp, 10.0_dp, "Quiver key, length = 10", labelpos="E") call savefig("quiver_simple_demo.svg") print *, "wrote quiver_simple_demo.svg" end program plot_quiver_simple_demo .. image-sg:: /auto_gallery/images_contours_and_fields/images/sphx_glr_plot_quiver_simple_demo_001.svg :alt: plot quiver simple demo :srcset: /auto_gallery/images_contours_and_fields/images/sphx_glr_plot_quiver_simple_demo_001.svg :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none wrote quiver_simple_demo.svg .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.038 seconds) .. _sphx_glr_download_auto_gallery_images_contours_and_fields_plot_quiver_simple_demo.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_quiver_simple_demo.f90 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_quiver_simple_demo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_