.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/meteorology/plot_wind_barbs.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_gallery_meteorology_plot_wind_barbs.py: Plotting Wind Direction Using Barbs =================================== This example demonstrates using barbs to plot wind speed contours and wind direction barbs from wind vector component input data. The vector components are co-located in space in this case. The magnitude of the wind in the original data is low and so doesn't illustrate the full range of barbs. The wind is scaled to simulate a storm that better illustrates the range of barbs that are available. .. GENERATED FROM PYTHON SOURCE LINES 14-62 .. image-sg:: /generated/gallery/meteorology/images/sphx_glr_plot_wind_barbs_001.png :alt: Wind speed during a simulated storm :srcset: /generated/gallery/meteorology/images/sphx_glr_plot_wind_barbs_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import iris import iris.plot as iplt import iris.quickplot as qplt def main(): # Load the u and v components of wind from a pp file infile = iris.sample_data_path("wind_speed_lake_victoria.pp") uwind = iris.load_cube(infile, "x_wind") vwind = iris.load_cube(infile, "y_wind") uwind.convert_units("knot") vwind.convert_units("knot") # To illustrate the full range of barbs, scale the wind speed up to pretend # that a storm is passing over magnitude = (uwind**2 + vwind**2) ** 0.5 magnitude.convert_units("knot") max_speed = magnitude.collapsed(("latitude", "longitude"), iris.analysis.MAX).data max_desired = 65 uwind = uwind / max_speed * max_desired vwind = vwind / max_speed * max_desired # Create a cube containing the wind speed windspeed = (uwind**2 + vwind**2) ** 0.5 windspeed.rename("windspeed") windspeed.convert_units("knot") plt.figure() # Plot the wind speed as a contour plot qplt.contourf(windspeed) # Add wind barbs except for the outermost values which overhang the edge # of the plot if left iplt.barbs(uwind[1:-1, 1:-1], vwind[1:-1, 1:-1], pivot="middle", length=6) plt.title("Wind speed during a simulated storm") qplt.show() if __name__ == "__main__": main() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.150 seconds) .. _sphx_glr_download_generated_gallery_meteorology_plot_wind_barbs.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_wind_barbs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_wind_barbs.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_