eplot icon indicating copy to clipboard operation
eplot copied to clipboard

How to use time data as input?

Open MaxGyver83 opened this issue 2 years ago • 2 comments

How can I tell eplot that my first column contains timestamps?

I have tried this:

echo '2022-12-15T12:18:26 104.8
2022-12-16T12:36:16 81.36
2022-12-17T14:06:25 79.875' | eplot -d -x 'xdata time; timefmt "%Y-%m-%dT%H:%M:%S"'

and

echo '2022-12-15T12:18:26 104.8
2022-12-16T12:36:16 81.36
2022-12-17T14:06:25 79.875' | eplot -d -x 'xdata time' -x 'timefmt "%Y-%m-%dT%H:%M:%S"'

(and without -x).

But it's still wrong.

(Sorry if my approach is completely wrong. I don't have experience with gnuplot. I just found eplot and thought it would be great if it's really that easy!)

This is the corresponding gnuplot script:

set terminal dumb
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%S"
set grid
plot 'data.txt' using 1:2 with lines

EDIT: Simplify tested eplot commands. Add working gnuplot script.

MaxGyver83 avatar Dec 16 '22 19:12 MaxGyver83

After looking into the code, I have doubts that x-axis options are supported at all.

The README says -x is for the label and other options:

-x x-options    (e.g. -x 'sigma')   Change options of the x-axis, e.g. the label but also other options.

The help looks like -x is for x-axis options in general:

 -x <x-axis-opt> provide x-axis options

But in the code, it looks like it's only about the label:

# ---- the x-axis label
when /^-x$|^--xlabel$/
	com=com+"set xlabel \""+checkOptArg(xargv,i)+"\";\n"
	i=i+1

I'll try to provide a pull request for this.

MaxGyver83 avatar Dec 18 '22 07:12 MaxGyver83

I can "inject" additional settings like this:

echo '2022-12-15T12:18:26 104.8
2022-12-16T12:36:16 81.36
2022-12-17T14:06:25 79.875' | eplot -d -x '";
set xdata time;
set timefmt "%Y-%m-%dT%H:%M:%S'

(See the unbalanced double quotes. This only works when you know how eplot handles the -x argument.)

But then gnuplot complains about the missing using spec:

echo '
set style line 1 lt 1 lw 1 pt 1 ps 0.5;
set style line 2 lt 3 lw 1 pt 1 ps 0.5;
set style line 3 lt 7 lw 1 pt 1 ps 0.5;
set style line 4 lt 4 lw 1 pt 4 ps 0.5;
set style line 5 lt 5 lw 1 pt 4 ps 0.5;
set style line 6 lt 2 lw 1 pt 2 ps 0.5;
set style line 7 lt 6 lw 1 pt 4 ps 0.5;
set style line 8 lt 8 lw 1 pt 4 ps 0.5;
set style line 20 lt 7 lw 1 pt 4 ps 0.5;
set terminal dumb;
set xlabel "";
set xdata time;
set timefmt "%Y-%m-%dT%H:%M:%S";
plot "/tmp/eplot20221218-119390-6bhk8e" with lines ls 1
'| gnuplot -persist

gnuplot> plot "/tmp/eplot20221218-119390-6bhk8e" with lines ls 1
                                                                ^
         line 0: Need full using spec for x time data

This can be fixed by:

diff --git a/eplot b/eplot
index 7e020ab..1497edb 100755
--- a/eplot
+++ b/eplot
@@ -437,6 +437,7 @@ class Controller
        def runSinFrSin(filename)
                styleArr=@oc["StyleIndices"].split(",")
                com="\""+filename+"\" "
+               com=com+"using 1:2 "
                com=com+"title \""+@oc["TitleString"]+"\" " if @oc["TitleString"]!=""
                com=com+"with "+@oc["LineType"]+" ls "+styleArr[0]
                plot(com,false)

But this might break other use cases. I think such a change should be done only by someone who knows about its consequences.

MaxGyver83 avatar Dec 18 '22 10:12 MaxGyver83