每小时两根柱状图的 GNU 绘图带宽

GNUplotting bandwidth with two bars per hour

大家好,我只想每小时绘制一次iperf3 up/down summaries in a graph. I'm thinking hour by hour in a bar chart with one bar being up and another for download speed like this。花了几个小时找出一个发送(向上)的柱状图,但不是第三个收到(向下)的柱状图。 Gnuplot 可以帮我解决问题并提供任何改进以使其看起来不错吗?非常感谢!

set term svg size 800,600 fname "Helvetica Neue" fsize 9 rounded dashed
set xdata time
set timefmt "%s"
set format x "%H\n%Y-%m-%d"
# Convert bytes to megabytes
set format y '%.0s%cB'
set style fill solid 0.7 border
plot '-' using 1:2 with boxes
1450848960 285806.25 206760
1450849177 169618.75 149460
1450850400 114761.625 101802.375
1450854001 66813.125 61197.375
1450857600 754362.5 580135
1450861200 21886.375 19150.5
1450864800 69255.875 63496.5
1450868400 60622.625 45791
1450872000 802862.5 628208.75
1450875600 818066.25 630898.75
1450879200 860511.25 646103.75
1450882800 841318.75 605322.5
1450886400 717462.5 609187.5
1450890000 768860 629053.75
1450893600 825708.75 595426.25
1450897200 826900 635977.5
1450900800 747992.5 582123.75
1450904400 747561.25 577085
1450908000 782548.75 542241.25
1450911600 817128.75 632105
1450915200 842408.75 605215
1450918800 808897.5 644612.5
1450922400 737481.25 551455
1450926000 789057.5 612383.75
1450929600 849720 639773.75

如果有任何更好的方法来尝试绘制 up/down 带宽,请告诉我。这是我用来生成上述 GNUplot 命令的 script

使用 boxes 绘图样式时,您必须手动将方框排列在一起。在下面的示例中,我使用 gnuplot heredoc(自版本 5 起可用)作为内联数据,因此我可以重用它:

$data <<EOD
1450849177 169618.75 149460
1450850400 114761.625 101802.375
1450854001 66813.125 61197.375
1450857600 754362.5 580135
1450861200 21886.375 19150.5
1450864800 69255.875 63496.5
1450868400 60622.625 45791
1450872000 802862.5 628208.75
1450875600 818066.25 630898.75
1450879200 860511.25 646103.75
1450882800 841318.75 605322.5
1450886400 717462.5 609187.5
1450890000 768860 629053.75
1450893600 825708.75 595426.25
1450897200 826900 635977.5
1450900800 747992.5 582123.75
1450904400 747561.25 577085
1450908000 782548.75 542241.25
1450911600 817128.75 632105
1450915200 842408.75 605215
1450918800 808897.5 644612.5
1450922400 737481.25 551455
1450926000 789057.5 612383.75
1450929600 849720 639773.75
EOD

set term svg size 800,600 fname "Helvetica Neue" fsize 9 rounded dashed
set xdata time
set timefmt '%s'
set style fill solid 0.7 border
set boxwidth 1800 absolute
plot $data using (timecolumn(1) - 1800):2 with boxes title 'up',\
     '' using 1:2 with boxes title 'down'

由于您想要绘制两个不同的数据集(即上带宽和下带宽),您从标准输入 (plot '-' ...) 读取的方法将不起作用 - 除非您提供两次输入数据。有关详细信息,请参阅此 SO-question

因此,我建议将输入数据写入临时文件tempin
绘图现在非常容易,使用直方图可以自动对输入进行聚类:

set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.9
set xtic rotate by -45 scale 0 font ",8"
set key top left

# Convert bytes to megabytes
set format y '%.0s%cB'

plot 'tempin' using 2:xticlabels(strftime("%H:00 %Y-%m-%d",column(1)-946684800)) t 'up', '' u 3 t 'down'

输出看起来像这样

请注意,我已经使用 gnuplot 4.4 测试了这个示例。如果您使用的是 gnuplot 5.0,您可能必须将 strftime("%H:00 %Y-%m-%d",column(1)-946684800) 更改为 strftime("%H:00 %Y-%m-%d",column(1)),因为时间 0 已从“1/1/2000”更改为“1/1/1970” .
(最后说明:如果你想发表你的结果,数字和单位之间应该有一个空白space:700kB -> 700 kB。)