
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/images_contours_and_fields/quiver_demo.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_images_contours_and_fields_quiver_demo.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_images_contours_and_fields_quiver_demo.py:


=======================================
Advanced quiver and quiverkey functions
=======================================

Demonstrates some more advanced options for `~.axes.Axes.quiver`.  For a simple
example refer to :doc:`/gallery/images_contours_and_fields/quiver_simple_demo`.

Note: The plot autoscaling does not take into account the arrows, so
those on the boundaries may reach out of the picture.  This is not an easy
problem to solve in a perfectly general way.  The recommended workaround is to
manually set the Axes limits in such a case.

.. GENERATED FROM PYTHON SOURCE LINES 14-22

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))
    U = np.cos(X)
    V = np.sin(Y)








.. GENERATED FROM PYTHON SOURCE LINES 23-30

.. code-block:: Python


    fig1, ax1 = plt.subplots()
    ax1.set_title('Arrows scale with plot width, not view')
    Q = ax1.quiver(X, Y, U, V, units='width')
    qk = ax1.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E',
                       coordinates='figure')




.. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_001.png
   :alt: Arrows scale with plot width, not view
   :srcset: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_001.png, /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 31-40

.. code-block:: Python


    fig2, ax2 = plt.subplots()
    ax2.set_title("pivot='mid'; every third arrow; units='inches'")
    Q = ax2.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
                   pivot='mid', units='inches')
    qk = ax2.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E',
                       coordinates='figure')
    ax2.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5)




.. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_002.png
   :alt: pivot='mid'; every third arrow; units='inches'
   :srcset: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_002.png, /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_002_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 41-54

.. code-block:: Python



    fig3, ax3 = plt.subplots()
    ax3.set_title("pivot='tip'; scales with x view")
    M = np.hypot(U, V)
    Q = ax3.quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022,
                   scale=1 / 0.15)
    qk = ax3.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E',
                       coordinates='figure')
    ax3.scatter(X, Y, color='0.5', s=1)

    plt.show()




.. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_003.png
   :alt: pivot='tip'; scales with x view
   :srcset: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_003.png, /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_003_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 56-63

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.axes.Axes.quiver` / `matplotlib.pyplot.quiver`
   - `matplotlib.axes.Axes.quiverkey` / `matplotlib.pyplot.quiverkey`


.. _sphx_glr_download_gallery_images_contours_and_fields_quiver_demo.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: quiver_demo.ipynb <quiver_demo.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: quiver_demo.py <quiver_demo.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: quiver_demo.zip <quiver_demo.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
