Code Block Evaluation in Org Mode

In Org mode, I try to “pave” data from a small Python-2-liner in Gnuplot, but I cannot figure out how to do this (Gnuplot images remain at 0kb). What I still have:

#+NAME: foo #+begin_src python :exports code import random for x in range (0,300): print random.randrange(1000), random.randrange(1000) #+end_src #+begin_src gnuplot :file gnuplot.png :exports results reset plot call_foo notitle #+end_src 

Who can do this job?

+4
source share
2 answers

My gnuplot in emacs is not working right now, so I cannot give a complete working answer. However, the :exports property for the python bit should be output , not code . In addition, in order to access this data in a gnuplot session, you will most likely want to read it in a table. Therefore, if you have python code like:

 #+name: foo #+begin_src python :exports results import random for x in range(0,300): print random.randrange(1000), random.randrange(1000) #+end_src 

you want your gnuplot session to be read in the result table as a variable

 #+name: plot-it(data = foo) #+begin_src gnuplot :file gnuplot.png plot data notitle #+end_src 

You may need to process the data variable in gnuplot code to make sure that this is the appropriate format. As I said above, I cannot verify this at this time, but this should be the starting point.

+1
source

I continued a little more with two questions: how can I get Python to release a table Org and how it can be evaluated by another Gnuplot block: Python could do

  • return [1, 2, 3]
  • print "| 1 | 2 | 3 |" for: raw output results
  • or print [a, b, c] for: output result table

I succeeded with evalutation with these blocks of code here:

 #+srcname: foo #+begin_src python :results output raw :exports code import random out="| %s | %s |" for x in range(0, 300): pair=(random.randrange(1000), random.randrange(1000)) print out % pair #+end_src #+begin_src gnuplot :var data=foo :file gnuplot.png :exports results reset set terminal png size 500,375 plot data u 1:2 notitle #+end_src 

However, with this setting, I always need to execute the Python block “manually” in order to generate the results # +: the foo block (which includes strings such as: | 629 | 884 |), and could not bring it to the auto-evaluation so far since

0
source

Source: https://habr.com/ru/post/1398491/


All Articles