From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: graphing from org-tables Date: Fri, 25 Jul 2008 12:07:00 -0700 Message-ID: <488a2450.1e078e0a.2bc0.181f@mx.google.com> References: <4889f6f8.29578c0a.3e24.ffff8395@mx.google.com> <20080725162527.GA54528@yog-sothoth.mohorovi.cc> Reply-To: Eric Schulte Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KMSd2-0001wD-3v for emacs-orgmode@gnu.org; Fri, 25 Jul 2008 15:07:00 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KMSd1-0001uu-4c for emacs-orgmode@gnu.org; Fri, 25 Jul 2008 15:06:59 -0400 Received: from [199.232.76.173] (port=38181 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KMSd1-0001ui-0M for emacs-orgmode@gnu.org; Fri, 25 Jul 2008 15:06:59 -0400 Received: from wf-out-1314.google.com ([209.85.200.171]:44900) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KMSd0-0001Jw-Kj for emacs-orgmode@gnu.org; Fri, 25 Jul 2008 15:06:58 -0400 Received: by wf-out-1314.google.com with SMTP id 28so2863310wfc.24 for ; Fri, 25 Jul 2008 12:06:57 -0700 (PDT) In-Reply-To: <20080725162527.GA54528@yog-sothoth.mohorovi.cc> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: James TD Smith Cc: Org-mode I had some time waiting for things to execute, so I condensed your process into a single command (borrowing heavily from org-export-table). (defun org-table/gnuplot (&optional x-col) "Plot the current table using gnuplot. Use a prefix argument to specify a column to use for the x-coordinates, to use the row number for the x-coordinates provide a prefix argument of 0." (interactive "p") (message (format "%S" x-col)) (unless (org-at-table-p) (error "No table at point")) (require 'org-exp) (require 'gnuplot) (org-table-align) ;; make sure we have everything we need (let* ((beg (org-table-begin)) (end (org-table-end)) (cols (save-excursion (goto-char end) (backward-char 3) (org-table-current-column))) (data-beg (if (and (goto-char beg) (re-search-forward org-table-dataline-regexp end t) (re-search-forward org-table-hline-regexp end t) (re-search-forward org-table-dataline-regexp end t)) (match-beginning 0) beg)) (skip (- (line-number-at-pos data-beg) (line-number-at-pos beg))) (exp-format (format "orgtbl-to-tsv :skip %d" skip)) (file (make-temp-file "org-table-plot"))) ;; export table (org-table-export file exp-format) (with-temp-buffer ;; write script (insert (org-table/gnuplot-script file x-col cols)) ;; graph table (gnuplot-mode) (gnuplot-send-buffer-to-gnuplot) (bury-buffer (get-buffer "*gnuplot*"))) (delete-file file))) (defun org-table/gnuplot-script (file x-col num-cols) (let ((plot-str "'%s' using %s:%d with lines title '%d'");; "\\\n ," script) (dotimes (col (+ 1 num-cols)) (unless (or (and x-col (equal col x-col)) (equal col 0)) (setf script (cons (format plot-str file (or (and x-col (format "%d" x-col)) "") col col) script)))) (concat "plot " (mapconcat 'identity (reverse script) "\\\n ,")))) On Friday, July 25, at 17:25, James TD Smith wrote: > On 2008-07-25 08:53:31(-0700), Eric Schulte wrote: > > > > Any advice for quick graphing of a table in org-mode? > > > > I have a setup for plotting data from tables. I'm not sure if it's exactly what > you want, but yoy may find it useful. > > 1. Add the following to your .emacs: > > (defun ahkt-plot-table (script) > "util function to export and plot a table using the supplied > gnuplot `script'" > (org-table-export) > (let ((cbuf (current-buffer)) > (cwin (selected-window))) > (save-restriction > (save-excursion > (find-file script) > (gnuplot-send-buffer-to-gnuplot) > (bury-buffer) > (bury-buffer (get-buffer "*gnuplot*")))) > (and (window-live-p cwin) (select-window cwin)) > (switch-to-buffer cbuf) > (delete-other-windows))) > > 2. Create a gnuplot script which plots data from a file. > > 3. Add the following properties to the headline containing the table. > TABLE_EXPORT_FILE > TABLE_EXPORT_FORMAT orgtbl-to-generic :skip 4 :splice t :sep "\t" > > 4. Add an org link in the table (it must be in the table otherwise the export > doesn't work) as below: > [[elisp:(ahkt-plot-table "")][plot table]] > > I suggest you put it at the top of the table. > You will then need to adjust the 'skip' parameter in the export format depending > on the number of lines at the top of the table which should not be exported > (hlines, more than one plotting link etc). > > 5. You should then be able to open the link, and get a plot of the table > contents. > > > -- > |---| > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode -- schulte