Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make several plots from the same standard input data in gnuplot?

Tags:

gnuplot

I want to have a single .plt file storing both data and gnuplot commands. My data looks like

# x1 y1 x2 y2
  1  2  3  4
  5  6  7  8

and corresponds to two plots: (x1,y1) and (x2,y2).

I know I can use "-" like:

plot "-" using 1:2
# x1 y1 x2 y2
  1  2  3  4
  5  6  7  8
e

But that would generate only one plot, i.e., (x1,y1). I'm trying to do something like

plot "-" using 1:2, "-" using 3:4
# x1 y1 x2 y2
  1  2  3  4
  5  6  7  8
e

but obviously that doesn't work since gnuplot expects a new set of data from the standard input for the second "-".

Notes:

  1. I cannot change the style of the data. It comes in four columns.
  2. It seems that I can do it with reread but that requires two files. I really want only one file.
like image 725
Mahdiyar Avatar asked Feb 12 '11 23:02

Mahdiyar


1 Answers

You can't do this without modifying something about the way you input the data. When feeding gnuplot data via standard input, it expects multiple data sets to be delimited with two blank lines between them, or to be interleaved on successive lines. The options are:

  • Feed the two data sets into different plot commands altogether.

  • Change the file format so that data sets have blank lines between them, then reference them all with index.

  • Change the file format so that alternating lines represent different data sets, then reference them all with every.

  • Put the data into one file, the plotting script into another, and then reference the data file more than once with different using clauses each time.

There's an intro to the every and index commands starting at How do I plot several data sets in a single file? Those are the only facilities built into gnuplot for this sort of thing, and neither does exactly what you were asking about. it's good you've already modified the data formatting, because this wasn't ever going to work as you'd originally hoped.

like image 135
Greg Smith Avatar answered Sep 19 '22 13:09

Greg Smith