1

I have two different files to plot in the gnuplot. they use a) different separator b) different time on x-axis

hence for each of them to plot separately I need to pass

set datafile separator
set timefmt

I would like to impose/overlay both data in a single graph such, that they are aligned with time

how could I do this?

4 Answers 4

2

The problem with the different separators can be addressed by using the format after the using modifier to specify a different separator for each file, e.g.:

plot 'file1.dat' u 1:2 '%lf,%lf'

plots a two column file with comma separator. See help\using for some more detail.

I am not expert of time formats, so I don't know how to deal with the timestamp format problem. But maybe you can use some function like strftime(). I never tried it, but it seems to me it does what you need.

Sign up to request clarification or add additional context in comments.

1 Comment

strftime() will work if the time data has no spaces in it (or the respective column separator character). Since gnuplot 5.0, the timecolumn() function accepts an additional individual format string
0

You're right, you will need to pass set datafile separator and set timefmt once per file. You can do it like this:

set terminal <whatever>
set output <whatever.wht>

set xdata time             # tell gnuplot to parse x data as time
set format x '%F'          # time format to display on plot x axis

set datafile separator ' ' # separator 1
set timefmt '%F'           # time format 1
plot 'file1'

set datafile separator ',' # separator 2
set timefmt '%s'           # time format 2
replot 'file2'

The replot command by itself replots the previous line, and if you specify another line to be plotted that will go on top of the first one like I did here.

1 Comment

This doesn't seem to work as replot will re-read the file in the previous command, but now the datafile separator isn't right, so gnuplot won't find any points (or at least not the right one).
0

It seems to me that you have 2 options. The first is to pick a datafile format and beat both datafiles into that format, maybe using awk:

plot '<awk "-f;" "{print $1,$2}" data1' using 1:2 w lines,\
     'data2' using 1:2 w lines

*Note, your awk command will almost certainly be different, this just shows how to use awk in an inline pipe.

Your second option is to use multiplot with explicit axes alignment:

set multiplot
set xdata time
set datafile sep ';' #separator for first file
set timefmt "..."  #time format for first file
set lmargin at screen 0.9
set rmargin at screen 0.1
set tmargin at screen 0.9
set bmargin at screen 0.1
unset key
plot 'data1' u 1:2 w lines ls 1 nontitle
set key #The second plot command needs to add both "titles" to the legend/key.
set datafile sep ',' #separator for second file
set timefmt "..." #time format for second file
unset border
unset xtics
unset ytics
#unset other stuff that you set to prevent it from being plotted twice.
plot NaN w lines ls 1 title "title-for-plot-1", \
    'data1' u 1:2 w lines ls 2 title "title-for-plot-2"

The plot NaN trick is only necessary if you want to have things show up correctly in the legend. If you're not using a legend, you can not worry about it.

1 Comment

Hi all, thanks for replies. At the end I did small python wrapper which takes my data and puts them into the other format. This allows to use single plot command, which automatically aligns the axis. the trick above works as well and I guess has to be used if both data sources are 'untweakable'
0

This works for me :

reset 
set term pngcairo
set output 'wall.png'
set xlabel "Length (meter)"
set ylabel "error (meter)"
set style line 1 lt 1 linecolor rgb "yellow" lw 10 pt 1
set style line 2 lt 1 linecolor rgb "green" lw 10 pt 1
set style line 3 lt 1 linecolor rgb "blue" lw 10 pt 1
set datafile separator ","
set key
set auto x
set xtics 1, 2, 9
set yrange [2:7]
set grid

set label "(Disabled)" at -.8, 1.8
plot  "file1.csv" using 1:2 ls 1 title "one" with lines ,\
  "file2.csv" using 1:2 ls 2 title "two" with lines ,\
  "file3.csv" using 1:2 ls 3 title "three" with lines
set output

Comments

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.