从csv读取gnuplot图例
我有一个data.csv文件,其结构如下:从csv读取gnuplot图例,gnuplot,Gnuplot,我有一个data.csv文件,其结构如下: n John Smith stats Sam Williams stats 1 23.4 44.1 2 32.1 33.5 3 42.0 42.1 目前,我正在gnuplot中使用以下命令进行绘图: plot 'data.csv' using
n John Smith stats Sam Williams stats
1 23.4 44.1
2 32.1 33.5
3 42.0 42.1
目前,我正在gnuplot中使用以下命令进行绘图:
plot 'data.csv' using 1:2 title 'John' with lines, '' using 1:3 title 'Sam' with lines
问题是如何从.csv的第一行检索名字,而不是手动输入
此外,如果我向表中添加一列,是否可以使其可调整,以便自动添加另一行具有适当标题的行?您说您有一个csv文件,因此我假设您的数据文件如下所示(并保存在infle.csv中): 如果您的Gnuplot版本足够新,则可以使用
columnhead
作为title
参数:
echo "
set datafile separator ','
plot 'infile.csv' using 1:2 with lines title columnhead
" | gnuplot --persist
或者使用键
选项:
echo "
set datafile separator ','
set key autotitle columnhead
plot 'infile.csv' using 1:2 with lines, '' using 1:3 with lines
" | gnuplot --persist
编辑-缩短标题
echo”
设置数据文件分隔符“,”
设置键自动字幕栏头
使用1:2和线条绘制“
输出:
后续问题的注释也可能与此相关。columnhead将打印整个专栏的标题。它太长并且妨碍了绘图(那里有越来越多的列),我只需要显示名字-这就是问题所在。@sashkello:不确定是否可以使用Gnuplot命令来实现这一点,我添加了一种使用GNU sed的方法。
echo "
set datafile separator ','
set key autotitle columnhead
plot 'infile.csv' using 1:2 with lines, '' using 1:3 with lines
" | gnuplot --persist
echo "
set datafile separator ','
set key autotitle columnhead
plot '< sed -r \"1 s/,([^ ]+)[^,]+/,\1/g\" infile.csv' using 1:2 with lines, '' using 1:3 with lines
" | gnuplot --persist