I am trying to make a plot showing the wind direction and wind speed as a vector (arrow) on a map.
I have a dataset which has the following structure (consisting of several lines):
lat lon winddirection(degrees) windspeed(kts)
52 -12 270 32
51 -13 271 33
.
.
.
I tried to use the quiver module, however, this seems to work with u/v components.
Does anyone know how I would make a plot showing the wind as arrows on a lat/lon 2D map?
Thanks,
CodePudding user response:
You can use winddirection
to compute u, v
components like this:
import numpy as np
import pandas as pd
# load your dataframe into the variable df
u = df["windspeed"] * np.cos(np.radians(df["winddirection"]))
v = df["windspeed"] * np.sin(np.radians(df["winddirection"]))
Then you do:
import matplotlib.pyplot as plt
import matplotlib.cm as cm
plt.figure()
plt.quiver(df["lat"], df["lon"], u, v, df["windspeed"], cmap=cm.viridis)