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: Eric Schulte
Subject: Re: [O] [babel] how to pass data to gnuplot from another block
Date: Sat, 23 Nov 2013 09:15:02 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Nick Dokos <address@hidden> writes:

> 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?
>

I think sh is more portable, but I guess almost any system should have
bash as well, I've just changed this default to bash.

Cheers,

>
>> #+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
>
>
>
>

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D



reply via email to

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