2015-04-01 40 views
2

我有一大组数据点。我尝试用boxplot来绘制它们,但某些异常值是完全相同的值,并且它们在一行旁边表示。我发现How to set the horizontal distance between outliers in gnuplot boxplot,但它并没有太多帮助,因为它显然是不可能的。如何在gnuplot中对boxplot异常值进行组合

是否可以将异常值组合在一起,打印一个点,然后在旁边的括号内打印一个数字以指示有多少个点?我认为这会使图形更具可读性。

有关信息,我有一个x值的三个boxlot和一个图中的六个时间。我正在使用gnuplot 5,并且已经使用了分号,这不会再减少距离。 我希望你能帮助!

编辑:

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 

这有什么代码已经到位,以实现它的最佳方式?

回答

0

没有选项可以自动完成此操作。在gnuplot的手动执行此操作所需的步骤是:

(在下文中我认为,数据文件data.dat只有一列。)

  1. 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) 
    
  2. 只算异常值,并将其写入到一个临时文件

    set table 'tmp.dat' 
    plot 'data.dat' using 1:($1 > upper_limit || $1 < lower_limit ? 1 : 0) smooth frequency 
    unset table 
    
  3. 情节没有异常值箱线图,并与labels绘图风格异常:

    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 
    

而这需要为每一个箱线图来完成。

免责声明:此程序应该基本上工作,但没有示例数据我无法测试它。

+0

谢谢!这个解决方案非常好。唯一的问题是,它打印出每一点,即使那些原本没有点的地方,如果你用boxplot打印它。你还可以看看我的原始文章中的编辑?我发布了我现在使用的东西,而且我不得不说我显然不适应Gnuplot。 ;)是否也可以改变点的大小和数字的大小? PS:它需要在第二个代码片段中是upper_limit和lower_limit。 ;) – Patrick 2015-04-01 10:09:41

+0

当绘制标签时,你必须检查计数的数量是否> 0,我编辑了答案。你可以像往常一样改变分数。 'ps 2',你也可以使用'font'选项来绘制'标签',比如'plot ... with labels font',12''。 – Christoph 2015-04-01 11:06:38

+0

出于测试目的,我使用了pdf终端,但我想在最后使用它与cairolatex。我意识到,cairolatex的点和标签根本不打印。你知道一个方法来绕过它吗? – Patrick 2015-04-01 13:40:35

相关问题