使用风速和度数绘制风场
Draw wind field using wind speed and degree
如何使用下面的代码像这张地图一样绘制风场?
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 ( - 202000000) : (0) : ( * SCALE) : 4 with arrows noborder
这里是 gnuplot 5.2 版本。您可以使用绘图样式 with vectors
.
特别提到的应该是:
set size ratio -1
这使得 x 和 y 的比例相同,例如45 度角实际上显示为 45 度角(检查 help size
)。取决于 x 和 y 范围和终端大小的系数 SCALE
会自动调整。
- 为了确保键(或图例)箭头的比例正确,我没有使用标准键(因为我不知道它相对于坐标的比例是多少),而是一个箭头和一个标签需要一些额外的编码。
代码:
### 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)):(*sin()) 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**cos()):(SCALE**sin()) \
w vectors as 1 notitle
### end of code
结果:
如何使用下面的代码像这张地图一样绘制风场?
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 ( - 202000000) : (0) : ( * SCALE) : 4 with arrows noborder
这里是 gnuplot 5.2 版本。您可以使用绘图样式 with vectors
.
特别提到的应该是:
set size ratio -1
这使得 x 和 y 的比例相同,例如45 度角实际上显示为 45 度角(检查help size
)。取决于 x 和 y 范围和终端大小的系数SCALE
会自动调整。- 为了确保键(或图例)箭头的比例正确,我没有使用标准键(因为我不知道它相对于坐标的比例是多少),而是一个箭头和一个标签需要一些额外的编码。
代码:
### 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)):(*sin()) 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**cos()):(SCALE**sin()) \
w vectors as 1 notitle
### end of code
结果: