summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfpi2022-06-19 20:30:08 +0200
committerfpi2023-02-19 18:37:22 +0100
commit715ac4dd67b766d3917c107e66609cecd700f2b2 (patch)
tree4867ee95e5b3e245e294ce64cb648e1a212b30f8
parent[WIP] nnnotmuch and nnmaildir backends (diff)
Add function to plot live data streamsdev+
Diffstat (limited to '')
-rw-r--r--gnuplot.org75
1 files changed, 75 insertions, 0 deletions
diff --git a/gnuplot.org b/gnuplot.org
index a9ec9f4..06359c9 100644
--- a/gnuplot.org
+++ b/gnuplot.org
@@ -4,6 +4,7 @@
First create a symlink to the desired config location.
#+begin_src shell :results silent :tangle tangle/symlink.sh :shebang "#!/bin/bash"
ln -siv $(pwd)/tangle/.gnuplot ~/
+ln -siv $(pwd)/tangle/gnuplotwindow.sh ~/.local/bin
#+end_src
* General Configuration
Start off by resetting most settings.
@@ -105,6 +106,80 @@ Support function to set x/y tic formatting with ~set format x formatter(".0","m"
#+begin_src gnuplot
formatter(prec,unit)=sprintf("%%%ss %%c%s", prec, unit)
#+end_src
+* Live data streams
+[[http://flux242.blogspot.com/2016/02/visualization-of-live-data-streams-with.html][Alex's blog: Visualization of live data streams with the gnuplot and bash]] describes how continuous data streams can be fed to gnuplot using the script below.
+#+begin_src sh :eval never :tangle tangle/gnuplotwindow.sh :tangle-mode (identity #o555)
+#!/usr/bin/env bash
+
+# Example:
+# nc -luk 6666 | jq --unbuffered -c 'select(.id==129)|.temperature_C' | \
+# GNUPLOT_TERM='sixelgd animate' ~/bin/gp/gnuplotwindow.sh 6000 "10:25" "Outside temperature;2;red"
+
+terminal="${GNUPLOT_TERM:-qt}" # terminal type (x11,wxt,qt,pdfcairo,pngcairo,..)
+output="${GNUPLOT_OUT}"
+output_ext="${GNUPLOT_EXT}"
+winsize=${1:-60} # number of samples to show
+yrange=${2:-0:100} # min:max values of displayed y range.
+ # ":" for +/- infinity. Default "0:100"
+shift;shift # the rest are the titles
+
+styles_def=( "filledcurves x1" "boxes" "lines" )
+# remove the color adjustment line below to get
+# default gnuplot colors for the first six plots
+# colors_def=("red" "blue" "green" "yellow" "cyan" "magenta")
+colors=( "${colors_def[@]}" )
+
+# parsing input plots descriptions
+i=0
+IFS=$';'
+while [ -n "$1" ]; do
+ tmparr=( $1 )
+ titles[$i]=${tmparr[0]}
+ styles[$i]=${styles_def[${tmparr[1]}]-${styles_def[0]}}
+ colors[$i]=${tmparr[2]-${colors_def[$i]}}
+ i=$((i+1))
+ shift
+done
+
+IFS=$'\n'
+samples=0 # samples counter
+(while read newLine; do
+ [ -n "$newLine" ] && {
+ #nf=$(echo "$newLine"|awk '{print NF}')
+ nf=0;TMPIFS=$IFS;IFS=$' \n'
+ for j in $newLine;do nf=$((nf+1));done
+ IFS=$TMPIFS
+ a=("${a[@]}" "$newLine") # add to the end
+ [ "${#a[@]}" -gt "$winsize" ] && {
+ a=("${a[@]:1}") # pop from the front
+ samples=$((samples + 1))
+ }
+ echo "set term $terminal noraise"
+ [[ -n "$output" ]] && {
+ echo "set output "\""${output}.$samples.${output_ext}"\"
+ }
+ echo "set yrange [$yrange]"
+ echo "set xrange [${samples}:$((samples+${#a[@]}-1))]"
+ echo "set style fill transparent solid 0.5"
+ echo -n "plot "
+ for ((j=0;j<nf;++j)); do
+ echo -n " '-' u 1:$((j+2)) t '${titles[$j]}' "
+ echo -n "w ${styles[$j]-${styles_def[0]}} "
+ [ -n "${colors[$j]}" ] && echo -n "lc rgb '${colors[$j]}'"
+ echo -n ","
+ done
+ echo
+ for ((j=0;j<nf;++j)); do
+ tc=0 # temp counter
+ for i in "${a[@]}"; do
+ echo "$((samples+tc)) $i"
+ tc=$((tc+1))
+ done
+ echo e # gnuplot's end of dataset marker
+ done
+ }
+done) | gnuplot 2>/dev/null
+#+end_src
* A4 plots
See [[https://milianw.de/blog/how-to-generate-proper-din-a4-sized-plots-with-gnuplot.html][How to generate proper DIN A4 sized plots with Gnuplot - Milian Wolff]].