{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Wind barbs\n\nDemonstration of wind barb plots.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\n\nx = np.linspace(-5, 5, 5)\nX, Y = np.meshgrid(x, x)\nU, V = 12 * X, 12 * Y\n\ndata = [(-1.5, .5, -6, -6),\n        (1, -1, -46, 46),\n        (-3, -1, 11, -11),\n        (1, 1.5, 80, 80),\n        (0.5, 0.25, 25, 15),\n        (-1.5, -0.5, -5, 40)]\n\ndata = np.array(data, dtype=[('x', np.float32), ('y', np.float32),\n                             ('u', np.float32), ('v', np.float32)])\n\nfig1, axs1 = plt.subplots(nrows=2, ncols=2)\n# Default parameters, uniform grid\naxs1[0, 0].barbs(X, Y, U, V)\n\n# Arbitrary set of vectors, make them longer and change the pivot point\n# (point around which they're rotated) to be the middle\naxs1[0, 1].barbs(\n    data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')\n\n# Showing colormapping with uniform grid.  Fill the circle for an empty barb,\n# don't round the values, and change some of the size parameters\naxs1[1, 0].barbs(\n    X, Y, U, V, np.sqrt(U ** 2 + V ** 2), fill_empty=True, rounding=False,\n    sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))\n\n# Change colors as well as the increments for parts of the barbs\naxs1[1, 1].barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',\n                 barbcolor=['b', 'g'], flip_barb=True,\n                 barb_increments=dict(half=10, full=20, flag=100))\n\n# Masked arrays are also supported\nmasked_u = np.ma.masked_array(data['u'])\nmasked_u[4] = 1000  # Bad value that should not be plotted when masked\nmasked_u[4] = np.ma.masked"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Identical plot to panel 2 in the first figure, but with the point at\n(0.5, 0.25) missing (masked)\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig2, ax2 = plt.subplots()\nax2.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. admonition:: References\n\n   The use of the following functions, methods, classes and modules is shown\n   in this example:\n\n   - `matplotlib.axes.Axes.barbs` / `matplotlib.pyplot.barbs`\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}