{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Plotting Wind Direction Using Quiver\n\nThis example demonstrates using quiver to plot wind speed contours and wind\ndirection arrows from wind vector component input data. The vector components\nare co-located in space in this case.\n\nFor the second plot, the data used for the arrows is normalised to produce\narrows with a uniform size on the plot.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import cartopy.feature as cfeat\nimport matplotlib.pyplot as plt\n\nimport iris\nimport iris.plot as iplt\nimport iris.quickplot as qplt\n\n\ndef main():\n    # Load the u and v components of wind from a pp file.\n    infile = iris.sample_data_path(\"wind_speed_lake_victoria.pp\")\n\n    uwind = iris.load_cube(infile, \"x_wind\")\n    vwind = iris.load_cube(infile, \"y_wind\")\n\n    # Create a cube containing the wind speed.\n    windspeed = (uwind**2 + vwind**2) ** 0.5\n    windspeed.rename(\"windspeed\")\n\n    # Plot the wind speed as a contour plot.\n    qplt.contourf(windspeed, 20)\n\n    # Show the lake on the current axes.\n    lakes = cfeat.NaturalEarthFeature(\n        \"physical\", \"lakes\", \"50m\", facecolor=\"none\"\n    )\n    plt.gca().add_feature(lakes)\n\n    # Add arrows to show the wind vectors.\n    iplt.quiver(uwind, vwind, pivot=\"middle\")\n\n    plt.title(\"Wind speed over Lake Victoria\")\n    qplt.show()\n\n    # Normalise the data for uniform arrow size.\n    u_norm = uwind / windspeed\n    v_norm = vwind / windspeed\n\n    # Make a new figure for the normalised plot.\n    plt.figure()\n\n    qplt.contourf(windspeed, 20)\n    plt.gca().add_feature(lakes)\n    iplt.quiver(u_norm, v_norm, pivot=\"middle\")\n\n    plt.title(\"Wind speed over Lake Victoria\")\n    qplt.show()\n\n\nif __name__ == \"__main__\":\n    main()"
      ]
    }
  ],
  "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.10.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}