Search code examples
gnuplot

How to plot arrows from angles of wind direction using vectors


I hope someone can help me. I'm trying to plot the angle of wind and colour the strength of the wind. The colour palette for wind strength is fine, but I'm having trouble converting the angle to a vector and plotting the arrow correctly - ideally with no 'tail'/ line.. This is a sample of the data file:

"Date", "Temp", "icon", "rain", "snow", "wind.speed", "wind.deg", "clouds.all"
"2019-12-29 18:00:00",5.58,"04n",,,"n",2.45,185,51,1025
"2019-12-29 21:00:00",5.36,"04n",,,"n",2.51,182,99,1025
"2019-12-30 00:00:00",5.34,"04n",,,"n",2.6,196,95,1025
"2019-12-30 03:00:00",5.28,"03n",,,"n",2.72,207,47,1024
"2019-12-30 06:00:00",5.23,"02n",,,"n",2.62,200,23,1024
"2019-12-30 09:00:00",5.47,"01d",,,"d",2.48,214,0,1024
"2019-12-30 12:00:00",9.82,"01d",,,"d",3.96,215,0,1023
"2019-12-30 15:00:00",8.94,"01d",,,"d",3.24,218,0,1021
"2019-12-30 18:00:00",6.18,"01n",,,"n",2.88,214,0,1022
"2019-12-30 21:00:00",5.75,"01n",,,"n",2.13,232,0,1022
"2019-12-31 00:00:00",5.82,"03n",,,"n",0.8,216,33,1022
"2019-12-31 03:00:00",5.18,"04n",,,"n",0.32,8,66,1022
"2019-12-31 06:00:00",5.37,"04n",,,"n",1.79,58,83,1022
"2019-12-31 09:00:00",5.1,"04d",,,"d",3.88,66,100,1023
"2019-12-31 12:00:00",7.97,"04d",,,"d",4.39,84,100,1025
"2019-12-31 15:00:00",8.52,"04d",,,"d",3.97,74,100,1025
"2019-12-31 18:00:00",7.83,"04n",,,"n",2.97,58,100,1026
"2019-12-31 21:00:00",7.93,"04n",,,"n",4.08,72,100,1027

This is the code I have so far - mostly from here: http://www.gnuplotting.org/vector-field-from-data-file/

#!/usr/bin/gnuplot
reset

set datafile missing "?"
set datafile separator ","

set terminal pngcairo true transparent truecolor size 1800, 500
set output '~/meteogram/vector.png'

set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"

set palette defined ( 0 '#ffffff', \
1 '#ffee00',\
2 '#ff7000',\
3 '#ee0000',\
4 '#7f0000')

xf(phi) = 10*cos(phi/180.0*pi+pi/2)
yf(phi) = 10*sin(phi/180.0*pi+pi/2)

plot FILE every 1 using 1:($7-yf($8)):(2*xf($8)):(2*yf($8)):7 with vectors head fixed filled lc palette

I'm trying to get a plot something like this image from a website enter image description here So just an arrow rotated to indicate the direction of the wind (coloured by strength) but plotted at the same y-value And I should add that I'm using Gnuplot 5.2 on Ubuntu


Solution

  •  set datafile missing "?"
     set datafile separator ","
     set xdata time
     set timefmt "%Y-%m-%d %H:%M:%S"
     set ang deg
     unset key
     unset colorbox
    
     plot 'wind.dat' using 1:7:("➤"):8:7 with labels rotate variable textcolor palette
    

    This example uses the unicode glyph U+27A4 "BLACK RIGHTWARDS ARROWHEAD". Other possible characters: →🠆🠊🠞🠮🢚🢡

    The precise appearance depends on the font and the font size. enter image description here