From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: using gnuplot's "splot" and "every" commands on org-mode table data Date: Fri, 03 May 2013 10:09:01 -0600 Message-ID: <87k3ncxeqt.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:51931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZO8f-0008Gt-6M for emacs-orgmode@gnu.org; Mon, 06 May 2013 12:19:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZO8d-00046b-JE for emacs-orgmode@gnu.org; Mon, 06 May 2013 12:19:45 -0400 Received: from mail-qe0-f52.google.com ([209.85.128.52]:35186) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZO8d-00046W-Ed for emacs-orgmode@gnu.org; Mon, 06 May 2013 12:19:43 -0400 Received: by mail-qe0-f52.google.com with SMTP id nd7so2127847qeb.25 for ; Mon, 06 May 2013 09:19:43 -0700 (PDT) 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: Paul Stansell Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Paul Stansell writes: > Hello everyone, > > I'd be grateful if someone would offer me advice on using gnuplot's > "splot" and "every" commands when plotting data from a table within > org-mode. > > As far as I can tell, these gnuplot commands do not work properly > because org-mode exports empty fields in tables as "" and gnuplot's > "every" and splot commands expect the data file to be formatted as a > datablock with blank lines marking the boundaries between datablocks. > (For the definition of a datablock, type "help glossary" at the > gnuplot prompt.) > > I'm using org-mode version 8.0.2 and emacs version 24.2.1 on a > Fedora-18 system > > > To illustrate my point, consider a blocked datafile called "block.dat" > containing the following: > > 1 1 2 > 1 2 5 > 1 3 10 > > 2 1 5 > 2 2 8 > 2 3 13 > > 3 1 10 > 3 2 13 > 3 3 18 > > For this file the gnuplot command > > #+begin_src gnuplot :var d="block.dat" :results silent > plot "$d" u 2:3 ev :::0::0, "" u 2:3 ev :::1::1, "" u 2:3 ev :::2::2 > #+end_src > > shows three separate lines of different colours as gnuplot > recognises the datafile as blocked data. > > Also, the following command produces a surface plot > > #+begin_src gnuplot :var d="block.dat" :results silent > splot "$d" u 1:2:3 > #+end_src > > However, if I put the same data in the table below > > #+tblname: data > | 1 | 1 | 2 | > | 1 | 2 | 5 | > | 1 | 3 | 10 | > | | | | > | 2 | 1 | 5 | > | 2 | 2 | 8 | > | 2 | 3 | 13 | > | | | | > | 3 | 1 | 10 | > | 3 | 2 | 13 | > | 3 | 3 | 18 | > > and use the following plot command > > #+begin_src gnuplot :var d=data :results silent > plot "$d" u 2:3 ev :::0::0, "" u 2:3 ev :::1::1, "" u 2:3 ev :::2::2 > #+end_src > > the result is a plot of a single line of the same colour as gnuplot > joins all of the points in the data file. This seems to be because > org-mode exports the table as > > "x" "y" "z" > 1 1 2 > 1 2 5 > 1 3 10 > "" "" "" > 2 1 5 > 2 2 8 > 2 3 13 > "" "" "" > 3 1 10 > 3 2 13 > 3 3 18 > > and gnuplot does not recognise this as a blocked data file because it > contains no blank lines. > > The same problem occurs for > > #+begin_src gnuplot :var d=data :results silent > splot "$d" u 1:2:3 > #+end_src > > which does not produce a gridded surface plot. > > Thanks for your help, > Hi Paul, While I can't claim to fully follow your gnuplot examples, i would recommend using an intervening shell code block to parse the Org-mode table data into something that gnuplot will ingest. If I understand your use case correctly, then something like the following should work. --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=example.org #+name: data | 1 | 1 | 2 | | 1 | 2 | 5 | | 1 | 3 | 10 | | | | | | 2 | 1 | 5 | | 2 | 2 | 8 | | 2 | 3 | 13 | | | | | | 3 | 1 | 10 | | 3 | 2 | 13 | | 3 | 3 | 18 | #+name: clean #+begin_src sh :var data=data :results file :file /tmp/data.gnuplot echo "$data" > /tmp/data.gnuplot #+end_src #+begin_src gnuplot :var data=clean(data) :results silent splot "$data" u 1:2:3 #+end_src --=-=-= Content-Type: text/plain If you really wanted to be fancy, gnuplot will let you specify shell transformations as part of the plotting command which would allow you to forego the intermediate code block. -- Eric Schulte http://cs.unm.edu/~eschulte --=-=-=--