Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting from two data sets delimited two different ways

Tags:

gnuplot

I need to plot data from a .csv file and from a white space separated file. Both sets of data need to appear on the same plot.

data1.dat

 #t   y
  1   1
  2   1
  3   1

and

data2.csv

 #t,y
  1,2
  2,2
  3,2

normally I would do the following if both were .csv sets:

 set datafile separator ','
 plot 'data1.csv' using 1:2,'data2.csv' using 1:2

Is there some way to include the setting of the separation character in the plot statement?

plot 'data1.dat' using 1:2,'data2.csv' using datafile separator ',' using 1:2

The above does not work and I tried many different variations of the above code....I had no luck.

like image 526
kxk7607 Avatar asked Jan 10 '13 16:01

kxk7607


2 Answers

AFAIK, there isn't a way to specify the separator. However, if you're in a POSIX compliant environment (and your gnuplot supports pipes -- which most do), you can farm the work out to awk pretty easily:

plot 'data1.dat' using 1:2,\
     "<awk -F, '{print $1,$2}' data2.csv" using 1:2
like image 74
mgilson Avatar answered Sep 22 '22 20:09

mgilson


You can give more than one character to set datafile separator, in your case ", ". All these are then individually treated as separators.

If your data files have a very difficult format: gnuplots using specifier accepts a libC scanf() format string

plot "-" us 1:2 "%lf,%lf"
1,2
2,3
3,4
e

You can give a different format string for every file on your plot command. Note that gnuplot only accepts "double" fp numbers for input, so you have to use the %le or %lf specifier.

Check help using examples, and here is a full description of the format.

like image 25
Karl Avatar answered Sep 24 '22 20:09

Karl