LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   gnuplot - do multiple plots from data file with built-in commands (https://www.linuxquestions.org/questions/linux-software-2/gnuplot-do-multiple-plots-from-data-file-with-built-in-commands-659156/)

Meson 07-29-2008 10:24 PM

gnuplot - do multiple plots from data file with built-in commands
 
Say I have the file testplot.p:

Code:

set xrange [-10,10]

plot "-" using 1:2 w l notitle, \
    "-" using 1:3 w l notitle

#col1 col2 col3
-10  100  -1000
-05    25  -250
  0    0      0
 05    25    250
 10  100  1000
end

What tends to happen is that I get an error if I try to plot from this data more than once. This will work:

Code:

set xrange [-10,10]

plot "-" using 1:3 w l notitle

#col1 col2 col3
-10  100  -1000
-05    25  -250
  0    0      0
 05    25    250
 10  100  1000
end


BrianK 07-30-2008 03:44 PM

Quote:

Originally Posted by Meson (Post 3230473)
Say I have the file testplot.p:
...

What tends to happen is that I get an error if I try to plot from this data more than once. This will work:

'-' is a special character that denotes standard in. This is to say that when you use '-' as a data source, your script will expect input from standard in which usually either user input or redirected script. In interactive gnuplot, it will give you a prompt asking for stdin.

The problem with the above example is that you're reading two instances of stdin which means that after you give it an "end" to signal the end of stdin, there's a second '-' that expects another stdin.

The solution then would be either to send the dataset to your script twice, i.e.:

Code:

plot '-' using ..., '-' using ...

data
data
data
end

data
data
data
end

or, better yet, is to use a file in place of '-', i.e.

Code:

plot 'some_file' using ..., 'some_file' using...
and then keep the data in a file. If the data is in a file, there's no need to use the keyword "end" as EOF signals the end of input.

ne pas 07-30-2008 03:52 PM

Quote:

What tends to happen is that I get an error if I try to plot from this data more than once.
Can't see an error message :(
Let me guess, it's
Quote:

warning: Skipping data file with no valid points
that's because after the first plot you're already at the end of your inline data, so there is nothing to read for the second plot.
That's the same with replot:
gnuplot>help datafile special-filenames
Quote:

[...]
If you use `'-'` with `replot`, you may need to enter the data more than once
(see `replot`).
[...]
If you use a datafile instead of "-" it should work as expected
Code:

set xrange [-10:10]

plot "datafile" using 1:2 notitle with lines, \
    "datafile" using 1:3 notitle with lines



All times are GMT -5. The time now is 12:25 AM.