问题描述
如何使用下面的代码(如此地图)绘制风场?
Time Temp Wind speed Wind direction Pressure
202000200 10.8836 2.4982 90.5014 80.7499
202000300 9.8425 2.6553 41.5163 90.0338
202000400 9.5351 2.4581 40.1018 80.5542
202000500 12.5231 4.1907 120.2293 84.4332
202000600 17.2069 3.1405 177.5542 87.0220
202000700 10.7297 5.5018 269.7194 81.5804
202000800 6.0049 4.2357 309.8655 68.6385
202000900 8.3194 2.5722 81.6993 78.4679
202001000 8.5940 4.2101 41.0358 84.9437
202001100 7.3084 3.8480 217.5551 70.2860
202001200 5.5046 3.0959 158.0296 68.9129
解决方法
- 我不清楚第一列的解释方式(年份+某物?),因此出于说明目的,我仅将最后4位数字作为x坐标。
- 有许多用于定义箭头形状的选项。请参阅“帮助设置样式箭头”。
- 绘图样式
with arrows
的数据字段为 x:y:length:angle
\
set angle degrees
unset key
set xzeroaxis
set xrange [0:*]
set title "Wind speed and direction"
SCALE = 10.
plot $WIND using ($1 - 202000000) : (0) : ($3 * SCALE) : 4 with arrows noborder
,
这是gnuplot 5.2版本。您可以使用绘图样式with vectors
。
特别要提到的是:
-
set size ratio -1
使x和y具有相同的比例,例如45度角确实显示为45度角(选中help size
)。因数SCALE
取决于x和y范围,并且端子尺寸会自动调整。 - 要确保键(或图例)箭头的比例正确,我不使用标准键(因为我不知道其相对于坐标的比例),而是一个箭头和一个需要一些标签的标签额外的编码。
代码:
### plot wind directions (gnuplot 5.2)
reset session
$Data <<EOD
# Time Temp Wind speed Wind direction Pressure
202000200 10.8836 2.4982 90.5014 80.7499
202000300 9.8425 2.6553 41.5163 90.0338
202000400 9.5351 2.4581 40.1018 80.5542
202000500 12.5231 4.1907 120.2293 84.4332
202000600 17.2069 3.1405 177.5542 87.0220
202000700 10.7297 5.5018 269.7194 81.5804
202000800 6.0049 4.2357 309.8655 68.6385
202000900 8.3194 2.5722 81.6993 78.4679
202001000 8.5940 4.2101 41.0358 84.9437
202001100 7.3084 3.8480 217.5551 70.2860
202001200 5.5046 3.0959 158.0296 68.9129
EOD
set size ratio -1
set angle degrees
myTimeFmt = "%Y%j%H"
# automatic determination of "optimum" value for SCALE with given data and terminal size
plot x # plot dummy graph otherwise GPVAL_TERM_XSIZE and GPVAL_TERM_YSIZE will be undefined
stats $Data u (timecolumn(1,myTimeFmt)):($3*sin($4)) nooutput
SCALE = (STATS_max_x-STATS_min_x)/(STATS_max_y-STATS_min_y)/GPVAL_TERM_XSIZE*GPVAL_TERM_YSIZE
set title "Wind speed and direction"
set format x "%j" timedate
set xzeroaxis lt -1
set grid xtics,mxtics lt -1,lt 0
set format y ""
unset ytics
# Legend arrow in correct scale
Speed = 2.0
KeyPosX = 0.8 # relative to graph
KeyPosY = 1.08 # relative to graph
set style arrow 1 filled size graph 0.015,15 fixed lc rgb "blue"
set arrow 1 from graph KeyPosX,graph KeyPosY rto first Speed*SCALE,0 as 1
set label 1 "2 m/s" at graph KeyPosX,graph KeyPosY right offset -1,0
plot $Data u (timecolumn(1,myTimeFmt)):(0):(SCALE*$3*cos($4)):(SCALE*$3*sin($4)) \
w vectors as 1 notitle
### end of code
结果: