0
votes

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:

  1. the X axis values don't match the previous plot
  2. the plot lines are merged on top of one-another

broken things

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?

1
I do not understand what the "two bad things" are that you mention... Could you post the two data files that you used for yoru "broken things" image, and explain what you would like to get instead? - user8153
OMG sorry! I composed this last night and then kernel panic. I plot data as is (blue line) and thru a conditional that only displays the "downslope" part of the data (purple line). I EXPECT the purple to exactly overlay the blue for the downslope part of the data. What's happening is the conditional values seem to be halved, which makes no sense to me. Output: imgur.com/a/se4yy Data: shown above in original post - Michael Sattler
set terminal svg size 512,384 \ fname "Gill Sans" fsize 9 rounded dashed linewidth 1 background rgb 'white' set datafile separator "," set key font ",6" file="frustration.csv" set output 'foobar.svg' stats file using ($2/3600):1 prefix "STATS" nooutput plot \ file using ($2/3600):1 with linespoints, \ file using ($2/3600):1:(sprintf("(%d, %d)", ($2/3600), $1)) notitle with labels center offset 3.4,.5, \ file using ((($2/3600) <= STATS_pos_min_y) ? $1 : 1/0) with linespoints - Michael Sattler
Questions: (1) Why does the conditional output seem to be halved? (2) How can I plot data conditionally with labels? Also, why was my markdown completely ignored? Sigh... - Michael Sattler
Edit: sorry, can't get a code block by any means :-/ proper code at gist.github.com/mickeys/738d49f69b10073d926c6af2188c3f9e - Michael Sattler

1 Answers

2
votes

The plot command for your whole data (purple line) is

plot file using ($2/3600):1  with linespoints

while that for the conditional data (blue line) is

plot file using ((($2/3600) <= STATS_pos_min_y) ? $1 : 1/0) with linespoints

This using statement selects only those data points for which ($2/3600) <= STATS_pos_min_y. However, you do not specify where on the x-axis those data points should be plotted, so gnuplot assumes it's just the line number in the data file (0,1,2,3,4). You have to specify the position on the x axis just like you did in the unconditional plot:

plot file using ($2/3600):((($2/3600) <= STATS_pos_min_y) ? $1 : 1/0) with linespoints

should do it.

By the way, formatting is rather limited in SO comments. To post code it's usually better to edit the question where you have more formatting options.