能否将绘图数据传递为字符串?
我的意思是像这样做:
plot "09-13-2010,2263.80 09-14-2010,2500" using 1:2 with lines
可以做类似于以下的操作:
set xdata time
set timefmt "%m-%d-%y"
plot "< echo '09-13-2010,2263.80 09-14-2010,2500' | tr ' ' '\n' | tr ',' ' '" using 1:2 with lines
当输入中含有 <
字符时,Gnuplot 会将其解释为从命令的输出中获取输入。每行记录以换行符分隔。组与组之间由一个空白记录分隔。在同一条记录中,默认列分隔符是空格。以上示例中使用了 tr
命令将数据拆分成多行,并将这些行重写为记录。
另一种将字符串中的数据绘制出来的方法是使用“-”输入说明符,然后通过命令行加载数据。程序可以轻松地发出以下指令:
set xdata time
set timefmt "%m-%d-%y"
plot '-' using 1:2 with lines
09-13-2010 2263.80
09-14-2010 2500
e
您最好使用类似以下内容的输入文件:
09-13-2010 2263.80
09-14-2010 2500
假设输入文件名为mydata.txt
,你可以使用以下命令绘制它:
set xdata time
set timefmt "%m-%d-%y"
plot 'mydata.txt' using 1:2 with lines
set xdata time
set timefmt "%m-%d-%y"
plot '-' using 1:2 title "Series 1" with lines,'-' using 1:2 title "Series 2" with lines
09-13-2010 2263.80
09-14-2010 2500
e
09-13-2010 2500
09-14-2010 2263.80
e