在gnuplot中标准化直方图bin [英] Normalizing histogram bins in gnuplot

查看:169
本文介绍了在gnuplot中标准化直方图bin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制一个直方图,其直方图由直方图中元素的数量标准化.

I'm trying to plot a histogram whose bins are normalized by the number of elements in the bin.

我正在使用以下

binwidth=5
bin(x,width)=width*floor(x/width) + binwidth/2.0
plot 'file' using (bin($2, binwidth)):($4) smooth freq with boxes

以获得基本的直方图,但我希望将每个bin的值除以bin的大小.我该如何在gnuplot中解决这个问题,或者在必要时使用外部工具?

to get a basic histogram, but I want the value of each bin to be divided by the size of the bin. How can I go about this in gnuplot, or using external tools if necessary?

推荐答案

在gnuplot 4.4中,函数具有不同的属性,因为它们可以执行多个连续的命令,然后返回一个值(请参见

In gnuplot 4.4, functions take on a different property, in that they can execute multiple successive commands, and then return a value (see gnuplot tricks) This means that you can actually calculate the number of points, n, within the gnuplot file without having to know it in advance. This code runs for a file, "out.dat", containing one column: a list of n samples from a normal distribution:

binwidth = 0.1
set boxwidth binwidth
sum = 0

s(x)          = ((sum=sum+1), 0)
bin(x, width) = width*floor(x/width) + binwidth/2.0

plot "out.dat" u ($1):(s($1))
plot "out.dat" u (bin($1, binwidth)):(1.0/(binwidth*sum)) smooth freq w boxes

第一个plot语句读取数据文件并为每个点增加一次sum,绘制一个零.

The first plot statement reads through the datafile and increments sum once for each point, plotting a zero.

第二个plot语句实际上使用sum的值对直方图进行归一化.

The second plot statement actually uses the value of sum to normalise the histogram.

这篇关于在gnuplot中标准化直方图bin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆