首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gnuplot:用gnuplot创建直方图

Gnuplot:用gnuplot创建直方图
EN

Stack Overflow用户
提问于 2021-05-26 14:44:37
回答 1查看 107关注 0票数 1

我想要创建一个柱状图从一个单一的列数据集出现的文本使用gnu图。我想要一些帮助。数据集的示例如下:

代码语言:javascript
复制
UDP
TCP
TCP
UDP
ICMP
ICMP
ICMP
TCP
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-26 18:02:37

但是,也有类似的问题,例如gnuplot automatic stack bar graph,仍然有点不同。下面的示例创建一些测试数据。如果您已经知道了关键字,并且希望它们按一定的顺序排列,请跳过创建唯一列表的步骤,然后自己定义Uniques = '...'。如果您有包含空格的关键字,则将项目括在双引号中可能是有利的。

keywords.

  • define help sum)

  • use

  • 通过使用sum函数创建查找函数
  • 的唯一列表(通过将查找索引作为x

检查选项平滑(check help smooth frequency) )。

脚本:(与gnuplot>=5.0.0一起工作)

代码语言:javascript
复制
### 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

结果:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67707295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档