author |
Steve Losh <steve@stevelosh.com> |
date |
Mon, 19 Aug 2024 08:56:24 -0400 |
parents |
eb8dc72799c8 |
children |
(none) |
# Basic Settings ---------------------------------------------------------- {{{
set encoding utf8
set terminal qt noraise
set samples 1000
# }}}
# Styles ------------------------------------------------------------------ {{{
set grid
set pointintervalbox 1.3
clr = "call '~/src/dotfiles/gnuplot-scripts/color.gp'"
bwp = "call '~/src/dotfiles/gnuplot-scripts/black-and-white-points.gp'"
bwl = "call '~/src/dotfiles/gnuplot-scripts/black-and-white-lines.gp'"
bwlp = "call '~/src/dotfiles/gnuplot-scripts/black-and-white-lines-points.gp'"
@clr
# }}}
# Constants --------------------------------------------------------------- {{{
tau = 2 * pi
e = 2.71828182845905
r2 = sqrt(2.0)
rfc3339 = "%Y-%m-%dT%H:%M:%S"
iso8601 = "%Y-%m-%dT%H:%M:%S"
# }}}
# Utility Functions ------------------------------------------------------- {{{
min(a, b) = (a<b) ? a : b
max(a, b) = (a>b) ? a : b
# }}}
# Linear Regression Fitting Functions ------------------------------------- {{{
baselrt(mm, bb, mprecision, bprecision) = sprintf(\
sprintf("%%.%dfx + %%.%df", mprecision, bprecision), \
mm, bb)
lr(x) = m * x + b
lrt(mp, bp) = baselrt(m, b, mp, bp)
lr2(x) = m2 * x + b2
lrt2(mp, bp) = baselrt(m2, b2, mp, bp)
lr3(x) = m3 * x + b3
lrt3(mp, bp) = baselrt(m3, b3, mp, bp)
lr4(x) = m4 * x + b4
lrt4(mp, bp) = baselrt(m4, b4, mp, bp)
# }}}
# Convenience Wrappers ---------------------------------------------------- {{{
# usage: @xrfc3339
csvinput = 'set datafile separator ","'
xrfc3339 = "set xdata time; set timefmt rfc3339"
yrfc3339 = "set ydata time; set timefmt rfc3339"
y_def = sprintf("set ytics format '%h'") # eval y_def()
y_eng(n) = sprintf("set ytics format '%." . n . "sx10^%S'") # eval y_eng(1) → 100.1 x 10⁶
# }}}
# Quick Plots ------------------------------------------------------------- {{{
# usage: @qpng
qpng = 'set terminal pngcairo size 1600,1200; set termoption font "Routed Gothic,18"; set output "plot.png"'
qpdf = 'set terminal pdfcairo size 16in,12in; set termoption font "Routed Gothic,20"; set output "plot.pdf"'
# }}}
# Exporting --------------------------------------------------------------- {{{
export(file, terminal) = sprintf( \
"set terminal push;" . \
"set terminal %s;" . \
"set output '%s';" . \
"replot;" . \
"set output;" . \
"set terminal pop;" . \
"print system('realpath %s | nnl | pbcopy');" \
, terminal, file, file)
export_pdf(file) = export(file . '.pdf', "pdfcairo")
export_png(file) = export(file . '.png', "pngcairo")
pdf = "eval export_pdf('graph')"
png = "eval export_png('graph')"
# }}}
# Histograms -------------------------------------------------------------- {{{
histogram_bin_width=1024*256
histogram_bin(x,width)=width*floor(x/width) + width/2.0
set boxwidth histogram_bin_width*0.9
set style fill solid 0.5
# plot 'sizes' using (histogram_bin($1,histogram_bin_width)):(1.0) smooth freq with boxes
# }}}
# Other ------------------------------------------------------------------- {{{
kdens(file, column, bandwidth) = sprintf( \
"stats '%s' using %d;" . \
"plot '%s' using %d:(1.0/STATS_records) smooth kdensity bandwidth %f;" \
, file, column, file, column, bandwidth)
cdf(file, column) = sprintf( \
"plot '%s' using %d:(1.0) smooth cnormal;" \
, file, column)
# }}}