0

I have two different text files with a list of numbers which I want to plot. One file contains the x values and the other the y values. I know how to plot them if they were in the same file but I don't know how to go about it for the separate files. How do I go about it? I am using GNUplot by the way.

If it is useful here are two small bits of data from both files:

x values
0
563
1563
2563
3563
4563
5563

corresponding y values
738500.0
683000.0
647000.0
623500.0
607500.0
Jonathan
  • 27
  • 5
  • What exactly do you want to plot? What is your x-value and what is your y-value? Maybe x and y from different files? Or row number as x and the other values as y? This is too little and unclear information. Please clarify in more detail. – theozh Mar 11 '21 at 18:07
  • I have edited my question. Hope it's more clear now – Jonathan Mar 11 '21 at 18:15
  • Problem solved? Question answered? Any feedback would be appreciated. – theozh Jun 08 '23 at 08:30

1 Answers1

2

I guess I have seen such a question already, but I can't find it right now. Well, Linux (in contrast to Windows) has some built-in tools where you can easily append two files line by line. If you want to do this in gnuplot only (and hence platform independent), the following would be a suggestion. Prerequisite is that you have your files already in a datablock. How to get this done see: gnuplot: load datafile 1:1 into datablock.

Code:

### merge files by line
reset session

$Data1 <<EOD
0
563
1563
2563
3563
4563
5563
EOD

$Data2 <<EOD
738500.0
683000.0
647000.0
623500.0
607500.0
EOD

maxRow = |$Data1| <= |$Data2| ? |$Data1| : |$Data2|   # find the shorter datablock

set print $Data
    do for [i=1:maxRow] {
        print $Data1[i][1:strlen($Data1[i])-1]." ".$Data2[i]
    }
set print

plot $Data u 1:2 w lp pt 7
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72