Tracking the battery discharge / charge on my phone. Data shaped like a 'V'. Charge percentage and elapsed time in seconds, like this:
100,0
74,8103
51,15304
24,23407
2,30609
23,33286
55,37360
76,40064
100,44132
Here's how I'm processing n files and plotting them together:
plots=""
my_xrange=0
files=system("ls -1B data/*.csv | sort -k2 -t '-'")
do for [ file in files ] {
this="'".file."' ".'using ($2/3600):1 notitle, '
plots=plots.this
}
eval('plot '.plots)
(happy plot elided because of too many links)
Then the boss comes by and says the "uphills" are distracting, can I plot just the "downhills" pretty please? No worries, stats will give me the minima, so I xrange. Woot!
plots=""
my_xrange=0
files=system("ls -1B *.csv | sort -k2 -t '-'")
do for [ file in files ] {
stats file using ($2/3600):1 prefix "STATS" nooutput
if ( STATS_pos_min_y > my_xrange ) { my_xrange = STATS_pos_min_y }
this="'".file."' ".'using ($2/3600):1 notitle, '
plots=plots.this
}
print sprintf( 'stats: plot xrange is %.2f', my_xrange )
set xrange [0:my_xrange]
eval('plot '.plots)
xrange obliterates some uphills
I know there's got to be a way to just not plot the uphills, so I wind up with using conditional.
this="'".file."' ".'using (($2/3600) <= STATS_pos_min_y ? $1 : 1/0) notitle, '
which does effectively kill the uphills, but does two bad things to the plot:
- the X axis values don't match the previous plot
- the plot lines are merged on top of one-another
I need to use $2/3600 because I want things to be expressed in terms of hours. Oh, sure, I could write a script to massage the data before it even gets to gnuplot, but that's admitting defeat.
What have I not understood in my use of using?