在 Gnuplot 中绘制连续线以进行频率计数

Plotting continuous line in Gnuplot for frequency count

我正在尝试绘制 Gnuplot

中 (test_plot_bins.txt) 中可用的以下值的频率计数
-0.355534673
0.13217762
-0.842048585
-0.131302223
0.03265043
0.190827265
-0.25680709
-0.072149448
-0.156086803
0.065009468
-0.003330263
-0.059023393
-0.017556788
-0.06090761
-0.205948548
-0.18360047

使用这个脚本

#!/usr/bin/gnuplot -persist

    
clear
reset
set key off
set border 3

set boxwidth 0.05 absolute

set style fill solid 1.0 noborder      
    
  
bin_width = 0.01;
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
  

plot 'test_plot_bins.txt' using (rounded()) :(1) smooth frequency with boxes

这是结果。怎么改成正常的线图?

其次,当我复制一个值使其计数变为 2 然后绘制它时,它突出并减少了其他值。这是它的样子

如何缩放计数为 1 的其他值也可见的绘图?

要获得线图,您可以将 with boxes 替换为 with lines。然而,这可能不是显示此类合并数据的最佳方式。我建议使用在线演示 bins.dem 作为指南。我复制在这里供参考。

#
# Demo illustrating the relationship between
# a binned histogram and a kernel density model of the same data.
#
$DATA << EOD
1   1
2   1
8   1
9   1
17  1
17  1
9   1
9   1
5   1
7   1
7   1
8   1
8   1
8   1
10  1
11  1
11  1
12  1
14  1
3   1
3   1
3   1
8   7
15  1
17  1
17  1
18  1
19  1
20  1
EOD

set title "Comparison of a binned histogram and\na kernel density model of the same data"

set style data lines
set xtics 1 norangelimit nomirror
set grid y
set yrange [0:5.5]
set style fill solid 0.5 noborder
set jitter spread 0.5

plot $DATA using 1 bins=20 with boxes title '20 bins', \
        '' using 1:(1) smooth kdensity bandwidth .5 lw 2 title 'smooth kdensity', \
        '' using 1:(.9) with impulse lc "black" title 'jittered data'

备注:

  • bins=20 会自动将数据沿 x 方向分成 20 个等宽的 bin。有一个可选关键字 binrange,但如果没有给出 binrange,则范围取自数据中找到的 x 值的极值。

  • set jitter 命令为点添加了一个小的位移,或者在这种情况下为脉冲添加了一个小位移,否则这些点将恰好位于彼此之上。它对框或线没有影响。

  • smooth kdensity 是生成平滑线的众多选项之一。有关完整文档,请参阅 gnuplot 文档。它生成一个函数 f(x),其中数据集中的每个点都充当高斯的中心,该高斯分布由与 x 的距离加权;结果曲线是这些贡献的总和。选择小于点间距的带宽可确保每个局部最大值都有自己的峰值。

  • boxeslinesimpulses 这三个表示中的每一个都可以独立绘制。该图结合了所有三种模式进行比较。