Gnuplot:使用Gnuplot创建直方图

Gnuplot:使用Gnuplot创建直方图,gnuplot,histogram,Gnuplot,Histogram,我想使用gnuplot从单列数据集中创建一个关于文本出现情况的直方图。我想要一些帮助。数据集的示例如下所示: UDP TCP TCP UDP ICMP ICMP ICMP TCP 也有类似的问题,例如:, 不过还是有点不同。 以下示例创建了一些测试数据。 如果你已经知道这些关键词,并且想拥有它们 按照一定的顺序,跳过创建唯一列表的步骤,自己定义Uniques='…'。如果您有包含空格的关键字,最好将项目括在双引号中 创建一个唯一的关键字列表 使用sum函数通过(mis)定义查找函数(检查帮助

我想使用gnuplot从单列数据集中创建一个关于文本出现情况的直方图。我想要一些帮助。数据集的示例如下所示:

UDP
TCP
TCP
UDP
ICMP
ICMP
ICMP
TCP

也有类似的问题,例如:, 不过还是有点不同。 以下示例创建了一些测试数据。 如果你已经知道这些关键词,并且想拥有它们 按照一定的顺序,跳过创建唯一列表的步骤,自己定义
Uniques='…'
。如果您有包含空格的关键字,最好将项目括在双引号中

  • 创建一个唯一的关键字列表
  • 使用sum函数通过(mis)定义查找函数(检查帮助sum)
  • 通过将查找索引设为x,使用绘图选项“平滑”(选中“帮助平滑频率”)
代码:

### 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).'"')
set table $Dummy
    plot Uniques='' $Data u (Uniques=addToList(Uniques,1),'') w table
unset table

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 code
结果:

### 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).'"')
set table $Dummy
    plot Uniques='' $Data u (Uniques=addToList(Uniques,1),'') w table
unset table

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 code

单列还是单行?数据集有多大,大约有多少项?对不起,单列。我不能把它写进一个专栏。请原谅格式化。这些项目是10个独特的项目,总共构成3000条记录。