Reputation: 434
I started using GNUPLOT from my software several years ago and it has been very useful. My software generates a gnuplot command file including all data and then automatically calls GNUPLOT to plot this on the screen or a file. In some cases my software generates several lines as functions of a variable and in such a case I write a table with several columns but I did not manage to plot all curves from one table so the solution I found was to use several plot commands like
plot "-" using 3:2 with lines ls 1 title "X(LIQUID,CU)",\
"" using 4:2 with lines ls 2 title "X(FCC-A1,CU)",\
"" using 5:2 with lines ls 3 title "X(FCC-..O#2,CU)"
followed by the table repeated as many times I have plot commands (each time terminated by an "e"). Recently I have started to try to clean up my code and I discovered GNUPLOT has a "plot for" command and I tried to use this. For example:
plot for [i=3:5] './table1.dat' using i:2 with lines ls i columnhead(i)
works very well except that I would like to have the table in the same file as the GNUPLOT commands. It does not work to replace "./table1.dat" with "-" and then write the table (including 3 "e" at the end) because then I only get the first line plotted. It works if I repeat the table as before (with an "e" in between) but then I am back at the solution I already have. I have tried to add a "repeat" after the "e" but with no success. Earlier I have tried multiplot but then I had problems with scaling.
The plotting works fine it is just that I would like to avoid lengthy and rather confusing repeating (also in my ow code) of the same table for each line I want to plot. I am quire sure there must be some subtle way to do what I want but I cannot find it in the manual.
Bo Sundman
Upvotes: 2
Views: 269
Reputation: 48390
Since version 5.0 gnuplot has named data blocks, which allow you to define reusable inline data in a single file:
$Table <<EOD
1 11 111
2 22 222
3 33 333
EOD
plot for [i=2:3] $Table using 1:i with lines
Upvotes: 3
Reputation: 2332
The reason why you need to repeat the data is that gnuplot is plotting as it is reading. So it needs to read the data as many times as you ask for plots.
You could first write your data to some temporary file and then plot it:
F=system("mktemp /tmp/gnuplot-XXXXXXXX")
TITLES="A B C D"
set table F
plot "-" u 1:2:3:4:5 w table
0 1 2 3 4
1 6 7 8 9
e
plot for [i=2:5] F u 1:i tit word(TITLES,i-1)
The issue is that set table
doesn't support exporting the columheads AFAIK, hence the trick with a word list.
Upvotes: 0