iteration - gnuplot:从同一输出上的不同数据文件创建多个箱线图
问题描述
我有一组文件,其中包含我想要生成一组箱线图以便比较它们的数据。我可以将数据放入 gnuplot,但我不知道将每个文件分成自己的绘图的正确格式。
我已经尝试将所有必需的文件读入一个变量,这确实有效,但是当生成绘图时,所有箱线图都在彼此之上。我需要让 gnuplot 为每个新数据文件沿一个空间索引每个图。
例如,这会产生带有叠加图的输出:
FILES = system("ls -1 /path/to/files/*")
plot for [data in FILES] data using (1):($4) with boxplot notitle
我知道 X 位置是用 (1) 明确说明的,但我不确定用什么来替换它以获得每个地块的移动位置。这对其他图表类型来说不是问题,因为它们没有相同的字段来定位它们。
解决方案
您可以尝试以下方法。您可以通过索引访问文件列表中的文件word(FILES,i)
。检查help word
和help 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
结果:
推荐阅读
- django - 有没有办法从没有货币价值的 django-money MoneyField 中提取十进制值?
- ios - 在 Google DFP / AdManager iOS 上投放自适应广告的选项
- python - Python 2.x 并使用 %s、%d 等格式化程序
- swift - 关于在单例类中定义的常量
- java - java - 将数据插入数据库表中,其中输入数据的值决定将存储哪个表
- javascript - 使用纯 Javascript(无 SDK)对 AWS S3 进行 REST 调用
- hibernate - 如何解决休眠的staleStateException
- dialogflow-es - 在 Google 上生成动态列表
- css - 将 CSS 属性选择器与图标样式组件一起使用
- javascript - JS:分别从具有相同类的文本区域获取值