

.. _sphx_glr_gallery_pylab_examples_barb_demo.py:


=========
Barb Demo
=========

Demonstration of wind barb plots




.. rst-class:: sphx-glr-horizontal


    *

      .. image:: /gallery/pylab_examples/images/sphx_glr_barb_demo_001.png
            :scale: 47

    *

      .. image:: /gallery/pylab_examples/images/sphx_glr_barb_demo_002.png
            :scale: 47





.. code-block:: python

    import matplotlib.pyplot as plt
    import numpy as np

    x = np.linspace(-5, 5, 5)
    X, Y = np.meshgrid(x, x)
    U, V = 12 * X, 12 * Y

    data = [(-1.5, .5, -6, -6),
            (1, -1, -46, 46),
            (-3, -1, 11, -11),
            (1, 1.5, 80, 80),
            (0.5, 0.25, 25, 15),
            (-1.5, -0.5, -5, 40)]

    data = np.array(data, dtype=[('x', np.float32), ('y', np.float32),
                                 ('u', np.float32), ('v', np.float32)])

    # Default parameters, uniform grid
    ax = plt.subplot(2, 2, 1)
    ax.barbs(X, Y, U, V)

    # Arbitrary set of vectors, make them longer and change the pivot point
    # (point around which they're rotated) to be the middle
    ax = plt.subplot(2, 2, 2)
    ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')

    # Showing colormapping with uniform grid.  Fill the circle for an empty barb,
    # don't round the values, and change some of the size parameters
    ax = plt.subplot(2, 2, 3)
    ax.barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False,
             sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))

    # Change colors as well as the increments for parts of the barbs
    ax = plt.subplot(2, 2, 4)
    ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
             barbcolor=['b', 'g'],
             barb_increments=dict(half=10, full=20, flag=100), flip_barb=True)

    # Masked arrays are also supported
    masked_u = np.ma.masked_array(data['u'])
    masked_u[4] = 1000  # Bad value that should not be plotted when masked
    masked_u[4] = np.ma.masked

    # Identical plot to panel 2 in the first figure, but with the point at
    # (0.5, 0.25) missing (masked)
    fig2 = plt.figure()
    ax = fig2.add_subplot(1, 1, 1)
    ax.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')

    plt.show()

**Total running time of the script:** ( 0 minutes  0.121 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
