emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [babel] how to pass data to gnuplot from another block


From: Nick Dokos
Subject: Re: [O] [babel] how to pass data to gnuplot from another block
Date: Fri, 22 Nov 2013 12:27:50 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Eric Schulte <address@hidden> writes:


> The attached works fine for me (using sh since I don't have octave).
>
> #+name: uptime
> #+begin_src sh
>   paste <(echo -e "1\n5\n15") <(uptime|sed 's/^.*average: //;s/,//g'|tr ' ' 
> '\n')
> #+end_src
>

Just an fyi: I had to set org-babel-sh-command to "bash" for this to
work. Why is "sh" the default value of this variable?

> #+RESULTS: uptime
> |  1 | 0.02 |
> |  5 | 0.06 |
> | 15 | 0.05 |
>
> #+begin_src gnuplot :var data=uptime :results silent
>   set xrange [0:]
>   set yrange [0:]
>   set title "uptime"
>   set xlabel "minutes ago"
>   set ylabel "load"
>   plot data w lines
> #+end_src
>
> Ensure that the data you're passing into gnuplot is a table and not a
> string.  Gnuplot blocks handle tables by writing them to a file, and
> then replacing the variable with the file name.  As I recall gnuplot
> blocks assume string data already is a file name, so the variable is
> replaced directly.
>

Ah, that explains everything! I also didn't have octave on this machine
so I wrote a python block. Initially, I had

--8<---------------cut here---------------start------------->8---
#+name: foo
#+begin_src python
  x = ((1, 1), (2, 4), (3, 9))
  return "\n".join(["|%d | %d |" % (y[0], y[1]) for y in x])
#+end_src


#+RESULTS: foo
| 1 | 1 |
| 2 | 4 |
| 3 | 9 |
--8<---------------cut here---------------end--------------->8---

which looks like a table, but isn't: the gnuplot block was blowing
up just like Eric F's. I replaced it with

--8<---------------cut here---------------start------------->8---
#+name: foo
#+begin_src python
  x = ((1, 1), (2, 4), (3, 9))
  return x
#+end_src


#+RESULTS: foo
| 1 | 1 |
| 2 | 4 |
| 3 | 9 |
--8<---------------cut here---------------end--------------->8---

and everything is working. The only problem is that the results
*look* the same, so it's hard to see what the type is.

Nick






reply via email to

[Prev in Thread] Current Thread [Next in Thread]