Issue
I have a bunch of data points in a Pandas DataFrame that include wind_speed
, wind_dir
, and time
values.
I want to plot it so that I can get a plot similar to this:
However, I'm not sure how to do this. I've made plots using matplotlib
function of barbs
but wanted to get something like this plotted instead. I've been searching around trying to figure out how to create this sort of plot, but can't seem to find anything. Any suggestions?
Solution
You can use plt.quiver() for this. It needs four input parameters: X, Y define the arrow locations, U, V define the arrow directions. I created U
and V
based on wind_speed
and wind_dir
with basic trigonometry.
import matplotlib.pyplot as plt
import numpy as np
n = 10
wind_speed = np.random.random(n)
wind_dir = np.random.uniform(0, 2*np.pi, n)
time = list(range(n))
Y = [0] * n
U = np.cos(wind_dir) * wind_speed
V = np.sin(wind_dir) * wind_speed
plt.figure()
plt.quiver(time, Y, U, V)
Answered By - T C Molenaar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.