我想要创建一个柱状图从一个单一的列数据集出现的文本使用gnu图。我想要一些帮助。数据集的示例如下:
UDP
TCP
TCP
UDP
ICMP
ICMP
ICMP
TCP发布于 2021-05-26 18:02:37
但是,也有类似的问题,例如gnuplot automatic stack bar graph,仍然有点不同。下面的示例创建一些测试数据。如果您已经知道了关键字,并且希望它们按一定的顺序排列,请跳过创建唯一列表的步骤,然后自己定义Uniques = '...'。如果您有包含空格的关键字,则将项目括在双引号中可能是有利的。
keywords.
help sum)
检查选项平滑(check help smooth frequency) )。
脚本:(与gnuplot>=5.0.0一起工作)
### histogram: occurrences of keywords
reset session
# create some random test data
myKeywords = 'UDP TCP ICMP ABC WWW NET COM FTP HTTP HTTPS'
set print $Data
do for [i=1:3000] {
print word(myKeywords,int(rand(0)*10)+1)
}
set print
# create a unique list of strings from a column
addToList(list,col) = list.( strstrt(list,'"'.strcol(col).'"') > 0 ? '' : ' "'.strcol(col).'"')
Uniques = ''
stats $Data u (Uniques=addToList(Uniques,1),'') nooutput
N = words(Uniques)
Lookup(s) = (sum [_i=1:N] (s eq word(Uniques,_i) ? _idx=_i : 0), _idx)
set xrange [1:N]
set xtics out
set ylabel "Counts"
set grid x,y
set offsets 0.5,0.5,0.5,0
set boxwidth 0.8
set style fill transparent solid 0.5 border
set key noautotitle
plot $Data u (Lookup(strcol(1))):(1):xtic(1) smooth freq w boxes
### end of script结果:

https://stackoverflow.com/questions/67707295
复制相似问题