Reputation: 11
Is there any way to loop through a data file and extract specific points to plot them on the graph and then save the image on gnuplot
?
For instance my code so far:
save output 'graph.$n.png'
set label 4 at $x,$y point pointtype 5
plot 'C:\Users\Desktop\testdata.dat' using 2:3 w l
But I want to be able to change the 'x' and 'y' to be the values contained on one line, in the second and third column of the data file, then plot
them on the line graph, save the image, and then loop to the next line of data values. There's over 100 lines of data and I'd like a way to automate this graphing process.
All help is appreciated, thank you!!
Grace
Upvotes: 1
Views: 655
Reputation: 2344
I also do not know 'one-line' solution (without using external auxiliary file), but there is a 'prue Gnuplot' solution:
stats 'Grace.dat'
n=STATS_records
i=1
load 'hundreds_of_plots.plt'
where 'hundreds_of_plots.plt' is:
set term unknown
plot [i-1:i-0.5] 'Grace.dat' u 0:2
labelx=GPVAL_DATA_Y_MAX
plot [i-1:i-0.5] 'Grace.dat' u 0:3
labely=GPVAL_DATA_Y_MAX
set label 4 at labelx,labely point pointtype 5
set term png
set output "".i.'.png'
plot 'Grace.dat' u 2:3 w l
i=i+1
set output "".i.'.png'
if (i<=n) reread
Upvotes: 1
Reputation:
If you have awk, type in the terminal
awk 'BEGIN{i=1;while(i<100){printf "set term png;set output \"graph.%03d.png\";plot \"testdata.dat\" u 2:3 every 99999::"i"pt 5,\"testdata.dat\" u 2:3 w l;\n",i,i+5;i++}}' > test.plt
this generates the plotting file "test.plt", then open
gnuplot
and load the plotting file
load "test.plt"
Then it will generate 100 png files.
example: if the testdata.dat is the sin(x) function, you get 100 png files with serial numbers such as the figure below. For more than 100 files, replace
while(i<100)
Upvotes: 2