浮点数列的直方图

时间:2013-09-12 21:12:58

标签: unix histogram data-visualization

是否有一个通用的命令行Unix实用程序,允许您使用文件中的一列浮点数创建一个简单的直方图?

3 个答案:

答案 0 :(得分:1)

我无法想到任何标准的unix / gnu命令行实用程序。你可以创建一个单行脚本,如下所示:

awk '{nums[n++]=$1;if ($1 > max) max=$1} END {for (i=0; i<n; i++){ printf "%15.5f ",nums[i]; y=(nums[i] * 50)/max + 0.5; for(j=0; j<y; j++) printf "X";printf "\n";} }' < fileOfNumbers

这里是fileOfNumbers

0
0.3802513823806563
0.6970557413810001
0.8987761906537762
0.9550334815954414
0.8619219017964542
0.6420060782538214
0.339191808764492
0.009613420853058656
-0.2895238011697386
-0.5108307062853145
-0.6251519043638415
-0.6258919548129064
-0.5285343220241233
-0.3656723046807657
-0.17881005669083072
-0.008834451885644044
0.11272730604816542
0.16980020199496673
0.16398989653539123
0.11263040266652444
0.04327594873440613
-0.013960516502076581
-0.034374900159696395
-0.005077671284778755

这里是上面浮点数的输出直方图

0.00000 X
0.38025 XXXXXXXXXXXXXXXXXXXXX
0.69706 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0.89878 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0.95503 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0.86192 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0.64201 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0.33919 XXXXXXXXXXXXXXXXXXX
0.00961 XX
-0.28952 
-0.51083 
-0.62515 
-0.62589 
-0.52853 
-0.36567 
-0.17881 
-0.00883 X
0.11273 XXXXXXX
0.16980 XXXXXXXXXX
0.16399 XXXXXXXXXX
0.11263 XXXXXXX
0.04328 XXX
-0.01396 
-0.03437 
-0.00508 X

答案 1 :(得分:0)

这是一个Python one liner(在Python 2.7.5和3.3.2上测试)。它不适合浮点数(抱歉,OP),也不会将图形或组号绘制到箱中。但它会计算不是数字的东西。对于这种情况可能并不完全有用,但我认为变化是某种东西或其他东西的香料。

python -c'import collections as c, sys, pprint as p; p.pprint(c.Counter(map(int, sys.stdin.read().split())))' < fileOfNumber

答案 2 :(得分:0)

这里有一些python将浮点数的输入文件绘制为直方图和曲线

#  usage
#
#  python plot_file_of_floats.py  < /tmp/my_file_of_floats


import matplotlib.pyplot as plt
import sys

floats = map(float, sys.stdin.read().split()) # read input file from command line


plt.plot(floats, 'ro') # show floats as curve
plt.figure()           # permit another plot to get rendered

plt.hist(floats)  #  show histogram of floats
plt.show()

示例输入文件floats / tmp / my_file_of_floats

0
0.3802513823806563
0.6970557413810001
0.8987761906537762
0.9550334815954414
0.8619219017964542
0.6420060782538214
0.339191808764492
0.009613420853058656
-0.2895238011697386
-0.5108307062853145
-0.6251519043638415
-0.6258919548129064
-0.5285343220241233
-0.3656723046807657
-0.17881005669083072
-0.008834451885644044
0.11272730604816542
0.16980020199496673
0.16398989653539123
0.11263040266652444
0.04327594873440613
-0.013960516502076581
-0.034374900159696395
-0.005077671284778755

这里是如何使用上面的浮动文件

执行上面的代码
python plot_file_of_floats.py  < /tmp/my_file_of_floats

这是直方图

es6-module-uncaught-referenceerror-function-is-not-defined-at-htmlbuttonelemen

python上面的

也会显示相同浮点数的这条曲线

enter image description here