Last active
October 7, 2021 09:39
-
-
Save korjaa/d94dc6a4e1ffd42988b8589c60a20df3 to your computer and use it in GitHub Desktop.
Gnuplot spells
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Defaults | |
# ========== | |
set grid | |
set datafile separator "," | |
set print "-" # enable logging | |
print "Hello world" | |
set autoscale fix # Axes tight | |
# CSV column headers | |
# ==================== | |
set key autotitle columnhead | |
# PNG out | |
# ========= | |
fname="out" | |
# noenhanced -- remove special handling from _ | |
set terminal pngcairo size 1024,640 noenhanced | |
set output fname.".png" | |
# Derive output files from script name | |
plot_file = ARG0[:strstrt(ARG0, '.plt')] | |
data_file = plot_file.'csv' | |
png_file = plot_file.'png' | |
# Xdata is time | |
# =============== | |
set xdata time | |
set timefmt "\[%Y.%m.%d %H:%M:%S" | |
set format x "%H:%M:%S" | |
set xtics rotate by -15 left | |
# Binning (built-in) | |
# ==================== | |
plot fname.'.txt' using 1:(1) bins=50 with boxes fs solid 0.5 transparent | |
# Binning (function) | |
# ==================== | |
binwidth=3600 | |
set boxwidth binwidth | |
set style fill solid 0.1 | |
bin(x) = binwidth*floor(x/binwidth) | |
bin_center(x) = binwidth*floor(x/binwidth) + binwidth/2 | |
plot fname.'.txt' using (bin(timecolumn(1))):(1.0) smooth freq with boxes | |
# Horizontal line (note keyword first to return the axis) | |
# ================= | |
set arrow from \ | |
graph 0, first targ to \ | |
graph 1, first targ \ | |
nohead lt 7 lw 2 front | |
# Region of interest | |
# ===================== | |
roi1="\[2020.06.29 11:49:15" | |
set arrow from roi1, graph 0 to \ | |
roi1, graph 1 \ | |
nohead lt 7 lw 2 front | |
#set xtics add ("report" roi1) | |
set label "1st report\n(11:49:15)" \ | |
at roi1, graph 0.1 \ | |
front \ | |
offset 0.1,0 | |
# Multiplot | |
# =========== | |
# defined xrange is required for same scaling | |
xstart="\[2020.06.29 10:00:00" | |
xstop="\[2020.06.29 12:00:00" | |
set xrange [xstart:xstop] | |
# set layout | |
set multiplot layout 2, 1 title "Multiplot title" | |
# disable xtics | |
unset xtics | |
# adjust margins before plot | |
middle_gap=0.5 | |
set bmargin middle_gap | |
plot 'data.dump' using (bin(timecolumn(1))):(1.0) smooth freq with boxes fs solid 0.5 transparent | |
unset bmargin | |
# re-enable xtics | |
set xtics rotate by -15 left | |
# adjust margins before plot | |
set tmargin middle_gap | |
plot 'data.dump' using (bin(timecolumn(1))):(1.0) smooth freq with boxes fs solid 0.5 transparent | |
unset tmargin | |
# Loop through files in folder | |
# ============================== | |
do for [file in system('ls verify/*First.csv')] { | |
print file | |
plot file every 1000 using 1:2 with line title file | |
} | |
# If-else logic | |
# =============== | |
roi1="" | |
# http://gnuplog.blogspot.com/2011/07/conditional-statements.html | |
if (strstrt(fname, 'substring_in_fname') > 0) { | |
roi1="[2020.09.04 04:40:32" | |
} | |
if (roi1 ne "") { | |
set arrow from roi1, graph 0 to \ | |
roi1, graph 1 \ | |
nohead lt 7 lw 2 front | |
set label "event X happened here" \ | |
at roi1, graph 0.5 \ | |
front \ | |
offset 0.1,0 | |
} | |
# Creating discontinuity in a plot | |
# ================================== | |
# 1/0 results in undefined -> discontinuity | |
f(x) = x<a ? 1 : 1/0 | |
# Sync multiple files based on rising edge | |
# ========================================== | |
rising_edge=system("awk 'BEGIN{FS=\",\"}; $2 > 0.001 {print $1;exit}' data_time_comma_value.csv") | |
plot "data_time_comma_value.csv" using ($1 - rising_edge):2 with lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added second method of binning.