4

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

1 Answer 1

4

It is possible to do something like:

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

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

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: alt text

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

The previous example gives: alt text

Sign up to request clarification or add additional context in comments.

2 Comments

And is there a way to plot this way: plot '-' using 1:2 with lines... two functions? I trie to separate this with a coma but it didn't work.
You need to set a full using spec for each function. Check out `help datafile' in the Gnuplot help system. I've added an example above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.