title: Plotting wind speed and wind direction over time
body: <p>I'm trying to make a plot that can display both wind speed and wind direction over time. A colleague suggested adding a line pointing in the wind direction to each point on a time-series plot of wind speed.</p>
  
  <p>I thought it would be fairly simple to calculate the line. I used trig formulas from <a href="https://math.stackexchange.com/a/656511">here</a>. However the plot is not displaying as I'd expect. All of the lines look as if they have zero slope rather than vary from -1 to 1.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>wdates = [   7.357325746759259E5;   7.357325747916667E5;   7.357325749074074E5;    7.357325750231481E5;   7.357325751388889E5;   7.357325752546296E5;   7.357325753703704E5;   7.357325754861111E5;   7.357325756018518E5;   7.357325757175926E5;   7.357325758333333E5;   7.357325759490741E5;   7.357325760648148E5];
  topspeed = rand(size(wdates)) * 2;
  
  toprdir = [0 pi/6 pi/4 pi/3 pi/2 2*pi/3 3*pi/4 pi 5*pi/4 4*pi/3 3*pi/2 5*pi/3 7*pi/4];
  toprdir = toprdir';
  
  h = figure(1);
  plot(wdates,topspeed,'s');
  datetick('x')
  hold all;
  
  %find slope
  topslopes = tan(toprdir);
  
  for i=1:length(wdates)
      %find start point.
      clear x;
      clear y;
      x(1) = wdates(i);
      y(1) = topspeed(i);
      d = .0001;
  
      %x(2) = d * cos(atan(topslopes(i))) + x(1); %did not work?
      %y(2) = d * sin(atan(topslopes(i))) + y(1); %did not work?
      x(2) = d * cos(toprdir(i)) + x(1);
      y(2) = d * sin(toprdir(i)) + y(1);
      plot(x,y);
  end
  </code></pre>
  
  <p><a href="https://i.imgur.com/KEiZm1c.png" rel="nofollow noreferrer">And here is the result</a>.</p>