我有这样的文件格式:
2014/3/12 18:02:36 1 SSID1
2014/3/12 18:02:37 1 SSID1
2014/3/12 18:02:38 2 SSID2
2014/3/12 18:02:39 1 SSID1
2014/3/12 18:02:39 3 SSID3
2014/3/12 18:02:39 3 SSID3
2014/3/12 18:02:39 2 SSID2
我创建了一个gnuplot脚本以使用日历方案进行绘制->以X表示日期,以Y表示小时,并为每个与SSID的连接指定了点。我使用lc变量生成与column(3)不同的颜色。
reset
clear
file_exists(file) = system("[ -f '".file."' ] && echo '1' || echo '0'") + 0
fontsize(x)=((GPVAL_TERM eq 'postscript') && \
(strstrt(GPVAL_TERMOPTIONS,"eps")!=0)) ? x*2 : x
set xdata time
set ydata time
set timefmt x "%Y/%m/%d"
set timefmt y "%H:%M:%S"
day = 360*24
set xtics 70*day
set format y "%H"
set format x "%B %d"
set ylabel "Time (Hour)"
set xlabel "Date (Month Day)" offset -1,0
set xlabel font 'Arial-Bold, 15"
set ylabel font 'Arial-Bold, 15"
set xtics rotate
set xtics font "Arial-bold, 15"
set ytics font "Arial-Bold, 15"
set style data points
set terminal png size 3200,2400
do for [i=2:2] {
if ( file_exists("data".i.".dat") ) {
set output sprintf("%s.png", "data".i)
set key box below
set title "Different SSID Wifi on color"
plot "data".i.".dat" using 1:2:3 linecolor variable pt 7 ps 1 t columnhead(4)
}
}
但是我没有正确的图例(键)。在我的代码中,我只有一个带有第一个SSID的框,该列的第(4)条具有正确的颜色...但是如何在此框中将所有SSID具有所有可变的颜色?
使用title columnheader(4)
,您选择第一行的第四列作为整个绘图的关键标题。为了获得正确的标题以及键中正确的线条颜色(请参见例如,Different color per dataset中与linecolor variable
有关的键颜色),最好生成一个包含所有唯一SSID的列表,然后对其进行迭代:
file = 'data2.dat'
SSIDs = system(sprintf('awk ''{print $4}'' %s | sort | uniq', file))
set xdata time
set ydata time
set timefmt x "%Y/%m/%d"
set timefmt y "%H:%M:%S"
day = 360*24
set xtics 70*day
set format y "%H"
set format x "%B %d"
set style data points
plot for [s=1:words(SSIDs)] file using (strcol(4) eq word(SSIDs, s) ? timecolumn(1) : 1/0):2:3 lc s pt 7 ps 1 t word(SSIDs, s)
注意,在绘制1/0
时,使用此with points
技巧效果很好。如果出于某种原因要绘制线,则必须使用例如grep
:
cmd(s, f) = sprintf('< grep ''%s'' %s', s, f)
plot for [s=1:words(SSIDs)] cmd(s, file) using 1:2:3 lc s pt 7 ps 1 t word(SSIDs, s)