2

extending the question I had asked earlier which can be found here, plotting multiple (x,y) co-ordinates in a single curve with gnuplot. I am trying to plot the bezier curves in gnuplot using 2 different files. Each (x,y) from the first file forms a bezier curve passing through the points from the second file. The first file has the co-ordinates like the following:

 x      y  
0.0    0.5     
0.12   0.1    
0.16   0.4    
0.2    0.35   
0.31   0.8    
0.34   0.6   
0.38   1.0    
0.46   0.2   
0.51   0.7    
0.69   0.9    

The second file has the co-ordinates as the following:

 x      y
0.00   0.7
0.04   0.74073082208
0.08   0.85926917792 
0.12   0.9 
0.16   0.9
0.2    0.9  
0.24   0.749720623086
0.28   0.874229601255
0.32   0.74073082208
0.36   0.8 
0.4    0.721178508605 
0.44   0.878821491395
0.48   0.761772990545
0.52   0.700774803388
0.56   0.723771273415
0.6    0.789508073675
0.64   0.864014272269
0.68   0.896743348931

Now, how do I merge these two files to plot a single graph. These two files don't have the same number of rows, but I guess that doesn't matter. The first curve would be between (x1,y1) and (x2,y2) from the first file which would continue till (x10,y10). In the curve between (x1,y1) and (x2,y2); the points (x1,y1), (x2,y2) and (x3,y3) from the second file lie.

I followed this link http://t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html to sort and concatenate the two files but got some weird lines which is totally wrong. These values should actually plot Bezier curves but not getting the graph. I have written the following gnuplot script to plot the concatenated data:

set term x11 persist
set title "Animation curves"
set xlabel "Time (secs.)"
set ylabel "Parameter"
set x2label "Phoneme1" offset -35
set pointsize 2
set key off
set style line 2 lt 0 lc 1 lw 2
set xrange [0.0:1.0]
set yrange [0.0:1.3]

plot [0.0:0.8] "< cat -n file1.dat" u 1:2 smooth csplines ls 1, "" u 1:(0.0):(0):(1.3) w vectors nohead ls 2, "" u ($1+0.005):(1):(sprintf("P %d", $0)) w labels, \
           "file1.dat" u 1:2 with points, \
           "file2.dat" u 1:2 with points, \    

I got the following error:

plot "< cat -n file1.dat" u 1:2 smooth csplines ls 1, "" u 1:(0.0):(0):(1.3) w vectors    nohead ls 2, "" u ($1+0.005):(1):(sprintf("P %d", $0)) w labels, "file1.dat" u 1:2 with points, "file2.dat" u 1:2 with points,                  
                          ^
"plot.gp", line 21: Cannot smooth: no data within fixed xrange!
6
  • To check if I understand your question: If you would have the two files in a single file you would simply plot the data. The tricky part is how to do that with gnuplot without merging those files before hand. Is that correct or is there "more" to it? Commented Sep 14, 2011 at 9:17
  • @Woltan Thank you for looking at my question. Finally I got a reply. Yes that's absolutely correct. I feel stupid that I couldn't think this way. If they could be merged in a single file then gnuplot would simply plot it without any trouble. The thing is, I generate these files in my python code. So if there is a way in python to merge two files and sort them in the concatenated file then that would do the trick. Commented Sep 14, 2011 at 9:38
  • Well I guess I found the answer. But as far as I know I have tried it but will try again. I would follow this t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html Commented Sep 14, 2011 at 10:02
  • Now I remember, I had tried this already sorting and concatenating but this didn't give me the right results. I should get the bezier curves from the data but got some random lines which is wrong. Commented Sep 14, 2011 at 10:25
  • You could get a problem when having multiple entries on for example x=0.12. Since you export that with python why not simple change the export routine and write one file with no multiple entries? Also you could use use matplotlib Commented Sep 14, 2011 at 10:38

1 Answer 1

4

The script below works on my machine. Maybe this is even what you are looking for...

set term x11 persist
set title "Animation curves"
set xlabel "Time (secs.)"
set ylabel "Parameter"
set x2label "Phoneme1" offset -35
set pointsize 2
set key off
set style line 2 lt 0 lc 1 lw 2
set xrange [0.0:1.0]
set yrange [0.0:1.3]

plot [0.0:0.8] "< cat file1.dat file2.dat | sort -n" u 1:2 smooth csplines ls 1, \
                         "" u 1:(0):(0):2 w vectors nohead ls 2, \
                         "" u ($1 + 0.005):(1):(sprintf("P %d", $0)) w labels, \
                         "file1.dat" u 1:2 w p, \
                         "file2.dat" u 1:2 w p 
Sign up to request clarification or add additional context in comments.

2 Comments

I was thinking and trying to do a wrong solution. Though there is no syntax error now. But it is not plotting the right way. It should only plot the curves between the points from file1.dat. The data from file2.dat are the points lying in between the curves from file1.dat.
I was just getting confused and thought this solution was wrong but in fact the graph is absolutely ok. What is wrong is, the labelling and drawing of vectors. Here this is happening for the data from both the files. But that should actually be for only file1.dat. Is this possible?

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.