是否可以将数据传递到字符串中?
我的意思是做这样的事情:
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 表明我们希望我们的输入来自命令的输出。 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
前面的例子给出:
关于string - 来自字符串的 gnuplot 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3709462/