Skip to content

Instantly share code, notes, and snippets.

@HelgeG
Created February 16, 2018 13:05
Show Gist options
  • Save HelgeG/ba950daf246479668fb1c598b1fd080e to your computer and use it in GitHub Desktop.
Save HelgeG/ba950daf246479668fb1c598b1fd080e to your computer and use it in GitHub Desktop.
Org-mode and gnuplot to track weight

Tracking Weight

In addition to showing weight development, the following serves as documentation on how to use orgplot and the spreadsheet module.

DateObservationTrendChange
[2017-09-10 Dom]85.185.1000.000
[2017-09-11 Seg]84.985.080-0.020
[2017-09-12 Ter]83.184.882-0.198
[2017-09-13 Qua]82.684.654-0.228
[2017-09-14 Qui]83.784.559-0.095
[2017-09-15 Sex]83.984.493-0.066
[2017-09-16 Sáb]83.784.414-0.079
[2017-09-17 Dom]83.984.363-0.051
[2017-09-18 Seg]83.584.277-0.086
[2017-09-19 Tue]83.484.189-0.088
[2017-09-20 Wed]82.584.020-0.169
[2017-09-21 Thu]82.383.848-0.172
[2017-09-22 Fri]81.883.643-0.205
[2017-09-23 Sat]82.883.559-0.084
[2017-09-24 Sun]82.383.433-0.126
[2017-09-25 Mon]82.583.340-0.093
[2017-09-26 Tue]82.983.296-0.044
[2017-09-27 Wed]82.683.226-0.070
[2017-09-28 Thu]81.483.043-0.183
[2017-09-29 Fri]81.782.909-0.134
[2017-09-30 Sat]82.082.818-0.091
[2017-10-01 Sun]82.382.766-0.052
[2017-10-02 Mon]82.482.729-0.037
[2017-10-03 Tue]81.782.626-0.103
[2017-10-04 Wed]81.382.493-0.133
[2017-10-05 Thu]81.782.414-0.079
[2017-10-06 Fri]82.382.403-0.011
[2017-10-07 Sat]81.382.293-0.110
[2017-10-08 Sun]81.882.244-0.049
[2017-10-09 Mon]82.382.2500.006
[2017-10-10 Tue]81.282.145-0.105
[2017-10-11 Wed]80.581.981-0.164
[2017-10-12 Thu]79.781.753-0.228
[2017-10-13 Fri]80.281.598-0.155
[2017-10-14 Sat]81.081.538-0.060
[2017-10-15 Sun]81.581.534-0.004
[2017-10-16 Mon]81.381.511-0.023
[2017-10-17 Tue]80.881.440-0.071
[2017-10-18 Wed]79.981.286-0.154
[2017-10-19 Thu]79.881.137-0.149
[2017-10-20 Fri]80.181.033-0.104
[2017-10-23 Mon]81.381.0600.027
[2017-10-24 Tue]80.781.024-0.036
[2017-10-25 Wed]80.180.932-0.092
[2017-10-26 Thu]80.180.849-0.083
[2017-10-27 Fri]79.880.744-0.105
[2017-10-30 Mon]82.580.9200.176
[2017-10-31 Tue]81.480.9680.048
[2017-11-01 Wed]80.880.951-0.017
[2017-11-02 Thu]81.480.9960.045
[2017-11-07 Tue]79.980.886-0.110
[2017-11-08 Wed]79.480.737-0.149
[2017-11-09 Thu]80.380.693-0.044
[2017-11-10 Fri]80.580.674-0.019
[2017-11-11 Sat]81.080.7070.033
[2017-11-13 Mon]81.280.7560.049
[2017-11-14 Tue]80.280.700-0.056
[2017-11-15 Wed]80.580.680-0.020
[2017-11-16 Thu]79.780.582-0.098
[2017-11-17 Fri]79.480.464-0.118
[2017-12-04 Mon]81.680.5780.114
[2017-12-06 Wed]80.580.570-0.008
[2017-12-11 Mon]81.080.6130.043
[2017-12-12 Tue]80.880.6320.019
[2017-12-14 Thu]80.180.579-0.053
[2018-01-02 Tue]82.580.7710.192
[2018-01-03 Wed]81.480.8340.063
[2018-01-05 Fri]81.380.8810.047
[2018-01-06 Sat]81.080.8930.012
[2018-01-08 Mon]81.780.9740.081
[2018-01-10 Wed]81.180.9870.013
[2018-01-11 Thu]81.481.0280.041
[2018-01-13 Sat]81.581.0750.047
[2018-01-14 Sun]82.281.1880.113
[2018-01-16 Tue]81.781.2390.051
[2018-01-19 Fri]80.581.165-0.074
[2018-01-23 Tue]81.181.159-0.006
[2018-01-24 Wed]81.081.143-0.016
[2018-01-25 Thu]80.781.099-0.044
[2018-01-26 Fri]80.381.019-0.080
[2018-01-29 Mon]82.181.1270.108
[2018-02-01 Thu]79.180.924-0.203
[2018-02-02 Fri]78.980.722-0.202
[2018-02-03 Sat]80.180.660-0.062
[2018-02-04 Sun]80.580.644-0.016
[2018-02-05 Mon]80.980.6700.026
[2018-02-06 Tue]80.680.663-0.007
[2018-02-12 Mon]80.480.637-0.026
[2018-02-13 Tue]79.980.563-0.074
[2018-02-14 Wed]79.980.497-0.066
[2018-02-15 Thu]79.780.417-0.080
[2018-02-16 Fri]78.180.185-0.232

Now, this shows an interesting thing. When a table is sent to gnuplot via Babel, the dates are formatted like 2017-09-13-00:00:00, so for gnuplot to interpret the x range correctly, we must let gnuplot know that we are dealing with time data, and explicitly declare the format.

Struggled with the date format for a while until I found this post: https://lists.gnu.org/archive/html/emacs-orgmode/2012-03/msg01019.html

To get vertical lines from trend to observation, I plot with yerrorbars. The 4 values are X, Y, minY maxY, so we get an observation at Y, and a line from the observation to the trend.

My latest discovery is that gnuplot can produce svg directly, by setting the terminal to svg and outputting the results as shown below:

reset
set terminal svg size 800,600
set title "Weight tracking - Helge"

set xlabel "Date of measurement"
set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"

set format x "%Y-%m-%d"
set xtics nomirror rotate by -45

set autorange x
set autorange y

set ylabel "Weight in kg"

unset bars
set rmargin 10
plot data u 1:3 smooth csplines lw 2 title 'Trend', \
     data u 1:2:2:3 w yerrorbars lw 1 pt 7 title 'Observation'

Formula explanation: To avoid referencing values outside the table range, check for current row in formula https://emacs.stackexchange.com/questions/32279/org-mode-add-formula-to-generate-delta-column

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment