首页 > 解决方案 > gnuplot:从同一输出上的不同数据文件创建多个箱线图

问题描述

我有一组文件,其中包含我想要生成一组箱线图以便比较它们的数据。我可以将数据放入 gnuplot,但我不知道将每个文件分成自己的绘图的正确格式。

我已经尝试将所有必需的文件读入一个变量,这确实有效,但是当生成绘图时,所有箱线图都在彼此之上。我需要让 gnuplot 为每个新数据文件沿一个空间索引每个图。

例如,这会产生带有叠加图的输出:

FILES = system("ls -1 /path/to/files/*")

plot    for [data in FILES] data using (1):($4)  with boxplot notitle

我知道 X 位置是用 (1) 明确说明的,但我不确定用什么来替换它以获得每个地块的移动位置。这对其他图表类型来说不是问题,因为它们没有相同的字段来定位它们。

标签: iterationgnuplotboxplot

解决方案


您可以尝试以下方法。您可以通过索引访问文件列表中的文件word(FILES,i)。检查help wordhelp words。下面的代码假设Data0*.dat您的目录中有一些数据文件。也许有一种更智能/更短的方法来实现 xtic 标签。

代码:

### boxplots from a list of files
reset session

# get a list of files (Windows)
FILES = system('dir /B "C:\Data\Data0*.dat"')

# set tics as filenames
set xtics ()    # remove xtics
set yrange [-2:27]
do for [i=1:words(FILES)] {
    set xtics add (word(FILES,i) i) rotate by 45 right
}

plot for [i=1:words(FILES)] word(FILES,i) u (i):2 w boxplot notitle
### end of code

结果:

在此处输入图像描述


推荐阅读