如果您不想要箭头,那么您可以尝试脉冲样式(使用脉冲而不是线条)
(如果您仍然想要顶部的线条,那么您可以绘制两次)。
如果您真的想要箭头,那么以下方法可能会有所帮助:它使用 for 循环(或排序)将垂直箭头添加到绘图中。
Gnuplot script, for loop within or adding to existing plot
具体来说:
创建一个文件 simloop.gp,如下所示:
count = count+1
#save the count to count.gp
system 'echo '.count.' > count.gp'
#load the simloop shell
system "./simloop.sh"
#draw the arrow
load 'draw_arrow.gp'
if(count<max) reread
然后创建一个看起来像这样的 simloop.sh 文件
#!/bin/bash
#read the count
count=$(awk -F, '{print $1}' count.gp)
#read the file
xcoord=$(awk -v count=$count -F, 'BEGIN{FS=" ";}{ if(NR==count) print $1}' simulation.dat)
ycoord=$(awk -v count=$count -F, 'BEGIN{FS=" "}{ if(NR==count) print $2}' simulation.dat)
dir=$(awk -v count=$count -F, 'BEGIN{FS=" "}{ if(NR==count) print $3}' simulation.dat)
#choose the direction of the arrow
if [ \"$dir\" == \"0\" ]; then
echo '' > draw_arrow.gp
fi
if [ \"$dir\" == \"1\" ]; then
echo 'set arrow from ' $xcoord' ,0 to '$xcoord','$ycoord' head' > draw_arrow.gp
fi
if [ \"$dir\" == \"2\" ]; then
echo 'set arrow from '$xcoord',0 to '$xcoord','$ycoord' backhead' > draw_arrow.gp
fi
然后创建一个看起来像这样的 Simulation.gp 文件:
count = 0;
max = 5;
load "simloop.gp"
set yrange[0:*]
plot "simulation.dat" u 1:2 w l
确保shell文件有可执行权限(chmod +wrx simloop.sh),加载gnuplot并输入
load "./simulation.gp"
这对我来说适用于数据文件
1 99 0
2 92.7 1
3 100.3 2
4 44.2 0
5 71.23 1
(为了测试我去掉了时间格式你应该可以把它放回去没有太多麻烦。)
然后我得到了这张图:
我认为这或多或少是你想要的。