diff --git a/docs/gallery_code/meteorology/plot_wind_speed.py b/docs/gallery_code/meteorology/plot_wind_speed.py index 79be64ddd7..fd03f54205 100644 --- a/docs/gallery_code/meteorology/plot_wind_speed.py +++ b/docs/gallery_code/meteorology/plot_wind_speed.py @@ -11,71 +11,50 @@ """ -import cartopy.crs as ccrs import cartopy.feature as cfeat import matplotlib.pyplot as plt -import numpy as np import iris -import iris.coord_categorisation +import iris.plot as iplt import iris.quickplot as qplt def main(): - # Load the u and v components of wind from a pp file + # 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") - ulon = uwind.coord("longitude") - vlon = vwind.coord("longitude") - - # The longitude points go from 180 to 540, so subtract 360 from them - ulon.points = ulon.points - 360.0 - vlon.points = vlon.points - 360.0 - - # Create a cube containing the wind speed + # Create a cube containing the wind speed. windspeed = (uwind ** 2 + vwind ** 2) ** 0.5 windspeed.rename("windspeed") - x = ulon.points - y = uwind.coord("latitude").points - u = uwind.data - v = vwind.data + # Plot the wind speed as a contour plot. + qplt.contourf(windspeed, 20) - # Set up axes to show the lake + # Show the lake on the current axes. lakes = cfeat.NaturalEarthFeature( "physical", "lakes", "50m", facecolor="none" ) + plt.gca().add_feature(lakes) - plt.figure() - ax = plt.axes(projection=ccrs.PlateCarree()) - ax.add_feature(lakes) - - # Get the coordinate reference system used by the data - transform = ulon.coord_system.as_cartopy_projection() - - # Plot the wind speed as a contour plot - qplt.contourf(windspeed, 20) - - # Add arrows to show the wind vectors - plt.quiver(x, y, u, v, pivot="middle", transform=transform) + # Add arrows to show the wind vectors. + iplt.quiver(uwind, vwind, pivot="middle") plt.title("Wind speed over Lake Victoria") qplt.show() - # Normalise the data for uniform arrow size - u_norm = u / np.sqrt(u ** 2.0 + v ** 2.0) - v_norm = v / np.sqrt(u ** 2.0 + v ** 2.0) + # Normalise the data for uniform arrow size. + u_norm = uwind / windspeed + v_norm = vwind / windspeed + # Make a new figure for the normalised plot. plt.figure() - ax = plt.axes(projection=ccrs.PlateCarree()) - ax.add_feature(lakes) qplt.contourf(windspeed, 20) - - plt.quiver(x, y, u_norm, v_norm, pivot="middle", transform=transform) + plt.gca().add_feature(lakes) + iplt.quiver(u_norm, v_norm, pivot="middle") plt.title("Wind speed over Lake Victoria") qplt.show() diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 4e6c581392..dc9246ce97 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -68,6 +68,9 @@ This document explains the changes made to Iris for this release 📚 Documentation ================ +#. `@rcomer`_ updated the "Plotting Wind Direction Using Quiver" Gallery + example. (:pull:`4120`) + #. `@trexfeathers`_ included `Iris GitHub Discussions`_ in :ref:`get involved `. (:pull:`4307`)