问题描述
是否有一种相对简单的方法来绘制离散数据的分布图?
Is there a relatively simple way to plot a graph of distribution of discrete data?
例如我们有一些从0到1的范围内的浮点值,而我们需要的是10个范围([0.0、0.1],[0.1、0.2],...,[0.9、1.0])上的图表许多给定的浮标都达到了各自的范围.
E.g. we have some set of float values over a range from 0 to 1 and what we need is a chart diagram over 10 ranges ([0.0, 0.1], [0.1, 0.2], ..., [0.9, 1.0]) of how many of given floats hit the respective range.
谢谢.
推荐答案
这可以通过频率图"轻松完成.如果设置了频率选项,则将所有具有相同x值的点替换为具有y值总和的单个点"(帮助平滑频率).这意味着,如果为每个点分配y值1,则结果将是具有特定x值的所有点的数量.
This can easily be done with a "frequency plot". If the frequency option is set "all points with the same x-value are replaced by a single point having the summed y-values" (help smooth frequency). This means if you assign to every point the y-value 1 the result will be the number of all points having a particular x-value.
现在,为了能够对一定范围内的所有点求和,您可以使用一个对数据值进行四舍五入的函数如此处建议
Now, in order to be able to sum up all points within a certain range you can use a function which rounds off the values of the data as suggested here
bin(x)=0.1*floor(x/0.1)
plot "datafile.txt" using (bin($1)):(1.0) smooth frequency with boxes
您可能还想通过set boxwidth
和set style fill
调整框的外观.
You might also want to tweak the appearance of the boxes with set boxwidth
and set style fill
.
这篇关于使用gnuplot进行离散分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!