.. _sphx_glr_gallery_images_contours_and_fields_quiver_demo.py: ======================================================== Demonstration of advanced quiver and quiverkey functions ======================================================== Known problem: the plot autoscaling does not take into account the arrows, so those on the boundaries are often out of the picture. This is *not* an easy problem to solve in a perfectly general way. The workaround is to manually expand the axes. .. code-block:: python import matplotlib.pyplot as plt import numpy as np from numpy import ma 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) .. code-block:: python plt.figure() plt.title('Arrows scale with plot width, not view') Q = plt.quiver(X, Y, U, V, units='width') qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E', coordinates='figure') .. image:: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_001.png :align: center .. code-block:: python plt.figure() plt.title("pivot='mid'; every third arrow; units='inches'") Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], pivot='mid', units='inches') qk = plt.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', coordinates='figure') plt.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5) .. image:: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_002.png :align: center .. code-block:: python plt.figure() plt.title("pivot='tip'; scales with x view") M = np.hypot(U, V) Q = plt.quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1 / 0.15) qk = plt.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', coordinates='figure') plt.scatter(X, Y, color='k', s=5) plt.show() .. image:: /gallery/images_contours_and_fields/images/sphx_glr_quiver_demo_003.png :align: center **Total running time of the script:** ( 0 minutes 0.137 seconds) .. only :: html .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: quiver_demo.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: quiver_demo.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_