3
votes

I have data files in two formats, one being .csv and the other being .dat. Is it possible to plot the data from these two files on the same graph?

For plotting the data from the .dat file I used the following command:

plot "test.dat" using 1:2 with lines

I intend to plot the data from .dat file using continuous line. This I am able to achieve.

And for plotting the data from the .csv file I used the following command:

set datafile separator ','
plot "test1.csv" using 1:2

I would like to plot the data from .csv file using dashed lines. i.e., something similar to this "- - - - - -"

A line of data from .dat file is

-8.14257e-01 2.04276e+00 0.00000e+00

and from .csv is

3.12487-03,1.58743-03

2
I think you need to provide more information about the files. Have you been able to plot the data from either of them with gnuplot? - matt
I am new to GNU plot. Yes I am able to plot the data from .csv and .dat separately. But I do not how to plot them on the same graph. - Aim
Maybe you can add to your question the plot commands you run to plot them separately. Then also include a description of what you would like the plot look like when they're plotted together. - matt
Did you try plot "test1.csv" using 1:2, "test.dat" using 1:2 w lines ? - matt
Yes. But the data from "test1.csv" is not plotted as this requires set datafile separator ',' Whereas if I use set datafile separator ',' data from "test.dat" is not plotted. - Aim

2 Answers

2
votes

One thing you can do is replot.

plot "test.dat" u 1:2 w lines
set datafile separator ','
replot "test.csv" u 1:2

That will add the second line to your plot. Another thing you could do is to specify the input format.

set datafile separator ','
plot "test.dat" u 1:2 "%lf %lf %lf", "test.csv"

Note on Gnuplot 5.2 I can plot both files without specifying anything.

plot "test.dat", "test.csv"

They both show up.

The docs for the format specification (help using, page 98):

Syntax: plot ’file’ using <entry> {:<entry> {:<entry> ...}} {’format’}

If a format is specified, it is used to read in each datafile record using the C library ’scanf’ function. Otherwisethe record is interpreted as consisting of columns (fields) of data separated by whitespace (spaces and/ortabs), but see datafile separator.

1
votes

You can specify multiple characters to set datafile separator. If the columns are separated by either a space or comma, use

set datafile separator " ,"
plot "test.dat", "test1.csv"

Note, that this works only if the columns are separated by a single space. Still, it might be useful to have a simple variant.