diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2023-11-15 00:02:08 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2023-11-15 00:02:08 +0300 |
commit | 495cc33733844aa9aa82f9f667e5d6625748f69e (patch) | |
tree | 666689e33f0b6222e18a38f5797e59c97067a728 | |
parent | 864f19750c3b58c8c09cfd57ef7622f6bdd38b04 (diff) | |
download | applause2-495cc33733844aa9aa82f9f667e5d6625748f69e.tar.gz |
Added Jupyter-support to Stream:gnuplot()
* Renders SVG into a cell instead of a separate window
* currently requires some not-yet-merged patch for ILua (see https://github.com/guysv/ilua/issues/5)
-rw-r--r-- | applause.lua | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/applause.lua b/applause.lua index d701330..702e1ce 100644 --- a/applause.lua +++ b/applause.lua @@ -896,11 +896,22 @@ function Stream:gnuplot() error("Cannot plot infinite stream") end + local cmd = "feedgnuplot --exit --lines --ymin -1 --ymax 1 --domain" + + local svg_file + if _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. + svg_file = os.tmpname() + cmd = cmd.." --terminal svg >"..svg_file + end + -- NOTE: We're not using Stream:pipe() here, so we can -- efficiently calculate a time index. -- FIXME: Using something like libplplot would be more -- efficient - local hnd = io.popen("feedgnuplot --exit --lines --ymin -1 --ymax 1 --domain", "w") + local hnd = io.popen(cmd, "w") hnd:setvbuf("full") local second = sec() @@ -912,6 +923,13 @@ function Stream:gnuplot() end) hnd:close() + + if _G._send_display_data then + _G._send_display_data{ + ['image/svg+xml'] = io.open(svg_file):read('*a') + } + os.remove(svg_file) + end end --- Print values of stream when they change. |