来自字符串的gnuplot图 [英] gnuplot plot from string

查看:91
本文介绍了来自字符串的gnuplot图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过传递以字符串形式绘制数据?

Is it possible to pass to plot data in a string?

我的意思是做这样的事情:

I mean do something like this:

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用于将您的数据分成几行,然后将这些行重写为记录.

Where the < character indicates to Gnuplot that we want our input from the output of a command. Gnuplot separates records with a newline. Groups of records are separated by a blank record. Within a record, the default column separator is a space. In the above example tr is used to split your data into lines, and the rewrite the lines into records.

从字符串绘制数据的另一种方法是使用-"输入说明符,然后从命令行加载数据.一个程序可以很容易地发出以下信息:

Another way to plot your data from a string is to use the "-" input specifier, and then load the data in from the command line. A program could easily emit the following:

set xdata time
set timefmt "%m-%d-%y"
plot '-' using 1:2 with lines
09-13-2010 2263.80
09-14-2010 2500
e

您最好的选择是使用输入文件,例如:

Your best bet is to use an input file like:

09-13-2010 2263.80
09-14-2010 2500

假设输入文件名为mydata.txt,则可以使用以下命令对其进行绘制:

Assuming the input file is named mydata.txt, you can then plot it with the commands:

set xdata time
set timefmt "%m-%d-%y"
plot 'mydata.txt' using 1:2 with lines

上面的所有示例都为您提供了类似的东西:

All the examples above give you something like:

如果要使用日期和-"输入来绘制两个数据系列,则可以执行以下操作:

If you want to plot two data series using dates and the `-' input you could do the following:

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

前面的示例给出:

这篇关于来自字符串的gnuplot图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆