reddit / emacs

org-babel and graphical output (gnu octave)

where_Is_My_Towel · 2022-05-14 19:22
I'm looking for some advice on making org-mode's babel play nice with octave and python I want to be able to run a block like: `#+begin_src octave` `A = [1 2 3 4]` `B = [1 3 4 5]` `plot(A,B)` `#+end_src` and get the resulting plot as an image I can inline toggle. Looking at the current docs I can't quite figure out how to make that work (\[:session octave :output file\] as header arguments don't get me where I need to be) . I'm trying to mimic a literate programming environment provided by matlab's live editor. Advice?
dpoggio · 2022-05-15 00:23
Have you executed `org-babel-execute-maybe`? Can you describe a bit more what the problem is?
organic-bookworm · 2022-05-15 09:47
See the ["Graphical output"](https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave.html#orga320881) in the Octave manual. I don't use Octave, but guess this should work: #+begin_src octave :results file A = [1 2 3 4]; B = [1 3 4 5]; figure( 1, "visible", "off" ); plot(A,B); print -dpng ../images/octave-chart.png; ans = "../images/octave-chart.png"; #+end_src
where_Is_My_Towel · 2022-05-15 13:58
So I did rtfm and have tried this, I maybe should have made that more explicit in my post. The suggested code posted returns an error: ​ error: print: directory ../images does not exist error: called from print at line 426 column 7 ​ and (sadly) no image.
where_Is_My_Towel · 2022-05-15 14:04
org babel-execute-maybe gives: error: invalid call to script /usr/share/octave/7.1.0/m/help/ans.merror: called from ans ​ shortly after running it an octave window pops up, like a graph is going to be displayed, and is then killed. ​ Further problem description: I want to be make a graph with python or octave and then display that inline in the org file almost immediately after babel execution. Running and producing a file output that gets linked and can be toggled with toggle-inline-images would also be the ideal.
organic-bookworm · 2022-05-15 14:17
>error: print: directory ../images does not exist Welp, why not `mkdir ../images` or change the output file path then?
where_Is_My_Towel · 2022-05-15 15:04
this error is independent of ../images existing, first thing I tried.
where_Is_My_Towel · 2022-05-15 15:05
even hardcoded to a location on disk /home/user/ or /home/user I don't get a file.
organic-bookworm · 2022-05-15 17:22
FWIW, I've just installed Octave 7.1.0-2 and evaluated the exact same source block I've provided (doing `mkdir ../images` beforehand) -- it works as expected for me. I use Debian 10, Emacs 29.0.50, Org 9.6. Note, that code blocks by default are evaluated with respect to the buffer's `default-directory` variable (i.e. the dir `find-file` would open by default if you run it in your Org buffer). You may use `:dir` header for source blocks to override it. See [Choosing a working directory](https://orgmode.org/manual/Environment-of-a-Code-Block.html#Choosing-a-working-directory). Try printing into `default-directory`: #+begin_src octave :results file figure( 1, "visible", "off" ); sombrero; print -dpng file.png; ans = "file.png"; #+end_src P.S. Maybe I'm just shooting the wrong issue here, so excuse me if that's obvious to you.
where_Is_My_Towel · 2022-05-15 18:02
solved by updating my emacs and org version. Things now produce files correctly. Thank you!