diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-03-16 13:54:14 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-03-16 13:54:14 +0300 |
commit | 476261186fb6ca6bccd752546d18b2bd63eb1a64 (patch) | |
tree | 855ec4657a2e3cf23434daeed12f714ec78bd43b | |
parent | 1a12f69466d29721f8fa12c92850096339088f8c (diff) | |
download | applause2-476261186fb6ca6bccd752546d18b2bd63eb1a64.tar.gz |
Stream:gnuplot() now supports writing to an output filev0.1
* Especially useful to generate PDF plots for my thesis.
-rw-r--r-- | applause.lua | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/applause.lua b/applause.lua index a35dfe3..bf94d5d 100644 --- a/applause.lua +++ b/applause.lua @@ -879,9 +879,12 @@ end -- This is not allowed for infinite streams. -- Graphics will be displayed inline in Jupyter notebooks and when -- using the [kitty](https://sw.kovidgoyal.net/kitty/) terminal emulator. +-- @string[opt] file +-- If specified, render to the file name instead of into a window. +-- The file type is guessed from the file extension. -- @warning This requires the feedgnuplot script. -- @fixme gnuplot is not the ideal tool for plotting audio data. -function Stream:gnuplot() +function Stream:gnuplot(file) if self:len() == math.huge then error("Cannot plot infinite stream") end @@ -889,7 +892,10 @@ function Stream:gnuplot() local cmd = "feedgnuplot --exit --lines --ymin -1 --ymax 1 --domain" local svg_file - if _G._send_display_data then + if file then + assert(not file:find("'")) + cmd = cmd.." --hardcopy '"..file.."'" + elseif _G._send_display_data then -- Some extremely crude support for plotting directly into Jupyter ILua cells. -- NOTE: With io.popen() we cannot read and write to the pipe at the -- same time, so we must dump the file to disk. |