Discussion:
plotting 2 files with 2 different datafile separators
(too old to reply)
Jean-Pierre Coulon
2020-06-10 11:07:17 UTC
Permalink
In on file the data spaces are separated by a space and in the other one they
are separated with <tab>, requiring set datafile separator "\t".

How can I say plot "file1.txt", "file2.txt", to be compatible with both?
--
Jean-Pierre Coulon
Olaf Schultz
2020-06-10 11:55:20 UTC
Permalink
Post by Jean-Pierre Coulon
In on file the data spaces are separated by a space and in the other one
they are separated with <tab>, requiring set datafile separator "\t".
How can I say plot "file1.txt", "file2.txt", to be compatible with both?
Have you just tried it? Since I'am using now 20+ years I never had
problems with Space and \t as separator... neither in same file nor in
different files.

Greetings,

Olaf
Jörg Buchholz
2020-06-10 12:03:03 UTC
Permalink
Post by Jean-Pierre Coulon
In on file the data spaces are separated by a space and in the other one
they are separated with <tab>, requiring set datafile separator "\t".
How can I say plot "file1.txt", "file2.txt", to be compatible with both?
Here the default "whitespace" works with both separators (Tabulator and
Space).

set datafile separator whitespace

Jörg
Jean-Pierre Coulon
2020-06-10 13:43:02 UTC
Permalink
Post by Jörg Buchholz
Here the default "whitespace" works with both separators (Tabulator and
Space).
set datafile separator whitespace
In my second file I have: set timefmt "%d/%m/%Y %H:%M:%S" and now when I plot
the second file using 1:2 gnuplot believes the hour field is my second
column. Same with 1:3.

I know how to workaround with multiplot but I thought it could be simpler.
--
Jean-Pierre Coulon
Jörg Buchholz
2020-06-11 05:11:22 UTC
Permalink
Post by Jean-Pierre Coulon
Post by Jörg Buchholz
Here the default "whitespace" works with both separators (Tabulator and
Space).
set datafile separator whitespace
In my second file I have: set timefmt "%d/%m/%Y %H:%M:%S" and now when I
plot the second file using 1:2 gnuplot believes the hour field is my
second column. Same with 1:3.
I know how to workaround with multiplot but I thought it could be simpler.
There will be more than one solution. My solution is, bring both files
to the same separator. With "sytem" you can do it from inside gnuplot.


system "sed -i 's/\ /\t/g' sep_space.dat"
set datafile separator "\t"
plot 'sep_tab.dat' u 1:2 w lp, 'sep_space.dat' u 1:2 w lp



This "sed -i 's/\ /\t/g' sep_space.dat" convert the space into a
tabulator, in the file "sep_space.dat".

Jörg
Jean-Pierre Coulon
2020-06-11 06:21:07 UTC
Permalink
Post by Jörg Buchholz
Post by Jean-Pierre Coulon
I know how to workaround with multiplot but I thought it could be simpler.
There will be more than one solution. My solution is, bring both files
to the same separator. With "sytem" you can do it from inside gnuplot.
Thanks, but I am with Windows. But I know how to process either file in
Fortran. Or I'll ask the enthusiast who provided the files to standardize
either one :-)
--
Jean-Pierre Coulon
Olaf Schultz
2020-06-11 07:18:21 UTC
Permalink
Post by Jean-Pierre Coulon
Post by Jörg Buchholz
Post by Jean-Pierre Coulon
I know how to workaround with multiplot but I thought it could be simpler.
There will be more than one solution. My solution is, bring both files
to the same separator. With "sytem" you can do it from inside gnuplot.
Thanks, but I am with Windows. But I know how to process either file in
Fortran. Or I'll ask the enthusiast who provided the files to
standardize either one :-)
install cygwin and then use gnuplot there... sed and awk and gnuplot are
available under cygwin.

Greetings,

Olaf
Jörg Buchholz
2020-06-11 09:37:12 UTC
Permalink
Post by Olaf Schultz
Post by Jean-Pierre Coulon
Post by Jörg Buchholz
Post by Jean-Pierre Coulon
I know how to workaround with multiplot but I thought it could be simpler.
There will be more than one solution. My solution is, bring both files
to the same separator. With "sytem" you can do it from inside gnuplot.
Thanks, but I am with Windows. But I know how to process either file in
Fortran. Or I'll ask the enthusiast who provided the files to
standardize either one :-)
install cygwin and then use gnuplot there... sed and awk and gnuplot are
available under cygwin.
I have a mix of both. On Windows I use the "Win-Gnuplot" and cygwin to
have these nice helpers from the linux/unix world.

Here is another solution with only gnuplot.

set datafile separator whitespace
set table 'space2tab.dat' separator tab
plot 'sep_space.dat' u 1:2 w table
set datafile separator "\t"
unset table
plot 'sep_tab.dat' w p, 'space2tab.dat' w p


Then you have a second dataset (sep_space.dat -> space2tab.dat) with
tabulator instead space separators. It works since version 5.2.2.


Jörg
Karl Ratzsch
2020-06-11 19:24:47 UTC
Permalink
Post by Jean-Pierre Coulon
Post by Jörg Buchholz
Here the default "whitespace" works with both separators
(Tabulator and
Space).
set datafile separator whitespace
In my second file I have: set timefmt "%d/%m/%Y %H:%M:%S" and now
when I plot the second file using 1:2 gnuplot believes the hour
field is my second column. Same with 1:3.
I know how to workaround with multiplot but I thought it could be simpler.
The timeformat specifier should win against any datafile separator.
At least I was pretty sure it used to. That however doesn´t seem to
be the case both in gp5.3rc1 and 4.6.6. Hmmm ....


$dat << EOD
03/04/2020 14:14:14 654
03/04/2020 15:15:15 543
03/04/2020 16:16:16 654
EOD

#set dataf sep ...

set xdata time
set timefmt "%d/%m/%Y %H:%M:%S"
plot $dat us (timecolumn(1)):3 w lp ps 3
Jörg Buchholz
2020-06-13 18:59:47 UTC
Permalink
Post by Karl Ratzsch
Post by Jean-Pierre Coulon
Post by Jörg Buchholz
Here the default "whitespace" works with both separators
(Tabulator and
Space).
set datafile separator whitespace
In my second file I have: set timefmt "%d/%m/%Y %H:%M:%S" and now
when I plot the second file using 1:2 gnuplot believes the hour
field is my second column. Same with 1:3.
I know how to workaround with multiplot but I thought it could be simpler.
The timeformat specifier should win against any datafile separator.
At least I was pretty sure it used to. That however doesn´t seem to
be the case both in gp5.3rc1 and 4.6.6. Hmmm ....
$dat << EOD
03/04/2020 14:14:14 654
03/04/2020 15:15:15 543
03/04/2020 16:16:16 654
EOD
#set dataf sep ...
set xdata time
set timefmt "%d/%m/%Y %H:%M:%S"
plot $dat us (timecolumn(1)):3 w lp ps 3
Thanks to point this out, this can result in less work. GP 5.0.5 Debian
Stretch.

Jörg

Loading...