gnuplot:在同一输出上从不同数据文件创建多个箱线图
gnuplot: Create multiple boxplots from different data files on the same output
我有一组文件,其中包含我想要生成一组箱形图以便比较它们的数据。我可以将数据导入 gnuplot,但我不知道将每个文件分成自己的图的正确格式。
我已经尝试将所有必需的文件读入一个变量,这确实有效,但是当生成图时,所有的箱线图都在彼此之上。我需要让 gnuplot 为每个新数据文件沿着一个 space 索引每个图。
例如,这会生成带有叠加图的输出:
FILES = system("ls -1 /path/to/files/*")
plot for [data in FILES] data using (1):() with boxplot notitle
我知道在 (1) 中明确说明了 X 位置,但我不确定用什么替换它以获得每个绘图的移动位置。这不是其他图表类型的问题,因为它们没有相同的字段来定位它们。
您可以尝试以下方法。
您可以通过 word(FILES,i)
按索引访问文件列表中的文件。检查 help word
和 help words
。下面的代码假定您的目录中有一些数据文件 Data0*.dat
。也许有一种 smarter/shorter 方法来实现 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
结果:
我有一组文件,其中包含我想要生成一组箱形图以便比较它们的数据。我可以将数据导入 gnuplot,但我不知道将每个文件分成自己的图的正确格式。
我已经尝试将所有必需的文件读入一个变量,这确实有效,但是当生成图时,所有的箱线图都在彼此之上。我需要让 gnuplot 为每个新数据文件沿着一个 space 索引每个图。
例如,这会生成带有叠加图的输出:
FILES = system("ls -1 /path/to/files/*")
plot for [data in FILES] data using (1):() with boxplot notitle
我知道在 (1) 中明确说明了 X 位置,但我不确定用什么替换它以获得每个绘图的移动位置。这不是其他图表类型的问题,因为它们没有相同的字段来定位它们。
您可以尝试以下方法。
您可以通过 word(FILES,i)
按索引访问文件列表中的文件。检查 help word
和 help words
。下面的代码假定您的目录中有一些数据文件 Data0*.dat
。也许有一种 smarter/shorter 方法来实现 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
结果: