如何在gnuplot中分组箱线图异常值

如何在gnuplot中分组箱线图异常值,gnuplot,boxplot,outliers,Gnuplot,Boxplot,Outliers,我有大量的数据点。我试着用箱线图来绘制它们,但是有些异常值是完全相同的值,并且它们在一条相邻的线上表示。我发现了,但是没有太大帮助,因为这显然是不可能的 是否可以将异常值分组,打印一个点,然后在其旁边的括号中打印一个数字,以指示有多少个点?我认为这将使它在图表中更具可读性 作为参考,我有三个箱线图,一个x值乘以一个图中的六。我正在使用gnuplot 5,并且已经使用了pointsize,它不再减少距离。 我希望你能帮忙 编辑: set terminal pdf set output 'dat.p

我有大量的数据点。我试着用箱线图来绘制它们,但是有些异常值是完全相同的值,并且它们在一条相邻的线上表示。我发现了,但是没有太大帮助,因为这显然是不可能的

是否可以将异常值分组,打印一个点,然后在其旁边的括号中打印一个数字,以指示有多少个点?我认为这将使它在图表中更具可读性

作为参考,我有三个箱线图,一个x值乘以一个图中的六。我正在使用gnuplot 5,并且已经使用了pointsize,它不再减少距离。 我希望你能帮忙

编辑:

set terminal pdf
set output 'dat.pdf'
file0 = 'dat1.dat'
file1 = 'dat2.dat'
file2 = 'dat3.dat'
set pointsize 0.2
set notitle
set xlabel 'X'
set ylabel 'Y'
header = system('head -1 '.file0);
N = words(header)

set xtics ('' 1)
set for [i=1:N] xtics add (word(header, i) i)

set style data boxplot
plot file0 using (1-0.25):1:(0.2) with boxplot lw 2 lc rgb '#8B0000' fs pattern 16 title 'A'
plot file1 using (1):1:(0.2) with boxplot lw 2 lc rgb '#00008B' fs pattern 4 title 'B'
plot file2 using (1+0.25):1:(0.2) with boxplot lw 2 lc rgb '#006400' fs pattern 5 title 'C'
for [i=2:N] plot file0 using (i-0.25):i:(0.2) with boxplot lw 2 lc rgb '#8B0000' fs pattern 16 notitle
for [i=2:N] plot file1 using (i):i:(0.2) with boxplot lw 2 lc rgb '#00008B' fs pattern 4 notitle
for [i=2:N] plot file2 using (i+0.25):i:(0.2) with boxplot lw 2 lc rgb '#006400' fs pattern 5 notitle

使用此代码实现它的最佳方法是什么?

没有自动完成此操作的选项。在gnuplot中手动执行此操作所需的步骤包括:

(在下面我假设数据文件
data.dat
只有一列。)

  • 使用
    stats
    分析数据,以确定异常值的边界:

    stats 'data.dat' using 1
    range = 1.5 # (this is the default value of the `set style boxplot range` value)
    lower_limit = STATS_lo_quartile - range*(STATS_up_quartile - STATS_lo_quartile)
    upper_limit = STATS_up_quartile + range*(STATS_up_quartile - STATS_lo_quartile)
    
  • 只计算异常值并将其写入临时文件

    set table 'tmp.dat'
    plot 'data.dat' using 1:($1 > upper_limit || $1 < lower_limit ? 1 : 0) smooth frequency
    unset table
    
  • 每个箱线图都需要这样做


    免责声明:此过程基本上可以工作,但由于没有示例数据,我无法对其进行测试。

    谢谢!这个解决方案真的很好。唯一的问题是它会打印出每个点,即使是那个些原本并没有点的点,若你们用boxplot打印的话。你能不能也看看我原帖中的编辑?我发布了我现在正在使用的东西,我必须说我在Gnuplot显然不太适应你是否也可以更改点大小和数字的大小?PS:在您的第二个代码段中,它需要是上限和下限打印标签时,必须检查计数数是否大于0,我编辑了答案。您可以像往常一样使用
    ps 2
    更改点大小,也可以在使用标签打印
    时使用
    font
    选项,如
    plot。。。使用标签font',12'
    。出于测试目的,我使用了pdf终端,但最后我想将其与cairolatex一起使用。我意识到使用cairolatex时,点和标签根本不打印。你知道绕过它的方法吗?我可以在脚本开头设置
    cairolatex
    终端时重现这个错误。在进行实际绘图之前,您只能直接设置
    cairolatex
    终端和输出文件,因为
    pdfcairo
    这无关紧要。我不知道为什么会这样。
    set style boxplot nooutliers
    plot 'data.dat' using (1):1 with boxplot,\
         'tmp.dat' using (1):($2 > 0 ? $1 : 1/0):(sprintf('(%d)', int($2))) with labels offset 1,0 left point pt 7