From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel] how to pass data to gnuplot from another block Date: Sat, 23 Nov 2013 09:15:02 -0700 Message-ID: <874n73gk70.fsf@gmail.com> References: <87d2lsbvy7.fsf@ucl.ac.uk> <87iovkihe6.fsf@gmail.com> <8738mol52h.fsf@alphaville.bos.redhat.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VkG1b-00029e-Up for emacs-orgmode@gnu.org; Sat, 23 Nov 2013 11:25:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VkG1W-0005wG-O6 for emacs-orgmode@gnu.org; Sat, 23 Nov 2013 11:25:39 -0500 Received: from mail-pd0-x22b.google.com ([2607:f8b0:400e:c02::22b]:35406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VkG1W-0005w8-7E for emacs-orgmode@gnu.org; Sat, 23 Nov 2013 11:25:34 -0500 Received: by mail-pd0-f171.google.com with SMTP id z10so2804015pdj.30 for ; Sat, 23 Nov 2013 08:25:33 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nick Dokos Cc: emacs-orgmode@gnu.org Nick Dokos writes: > Eric Schulte 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