如何解决gnuplot-绘图-第一行作为标签
gnuplot版本:5.4
我有以下格式的数据集:
Label1 Label2 Label3
1 2 3
2 5 6
我想使用plot作为命令,因为列数不是静态的,并且我想使用数据集的第一行作为标签。
当我使用时:
plot for [i=2:dataset_columns] 'dataset.dat' using ($1):($i) with lines axes x1y1
错误:
warning: bad data on line 1 of file dataset.dat
Column number or datablock line expected
问题: 如何编辑我的命令以打印数据,如何使用第一行作为标签?
谢谢您的帮助。
解决方法
在gnuplot控制台中,检查help plot for
。如果您读到最后,将会看到:
如果要继续迭代直到消耗完所有可用数据, 使用符号*代替整数。这可以用来 处理一行中的所有列,所有数据集(以2个空格分隔 行)或与模板匹配的所有文件。
示例:
plot for [i=2:*] 'datafile' using 1:i with histogram splot for [i=0:*] 'datafile' index i using 1:2:3 with lines plot for [i=1:*] file=sprintf("File_%03d.dat",i) file using 2 title file
代码:
### plot all columns until last column
reset session
$Data <<EOD
Label1 Label2 Label3
1 2 3
2 5 6
EOD
plot for [col=2:*] $Data u 1:col w l title columnhead
### end of code
添加 :(如果您有一个名为datafile.dat
的数据文件)
Label1 Label2 Label3
1 2 3
2 5 6
代码:
### plot all columns until last column
reset session
plot for [col=2:*] 'datafile.dat' u 1:col w l title columnhead
### end of code
结果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。