From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Can org show live charts? Date: Tue, 21 Oct 2014 19:15:59 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgiey-0000EL-Gj for emacs-orgmode@gnu.org; Tue, 21 Oct 2014 19:16:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xgiep-0003Rp-6H for emacs-orgmode@gnu.org; Tue, 21 Oct 2014 19:16:12 -0400 Received: from smtp.andrew.cmu.edu ([128.2.105.202]:46840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgiep-0003RY-1O for emacs-orgmode@gnu.org; Tue, 21 Oct 2014 19:16:03 -0400 In-Reply-To: (Tom's message of "Tue, 21 Oct 2014 19:39:15 +0000 (UTC)") 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: Tom Cc: emacs-orgmode@gnu.org I think the answer is sort of. I am no idle timer guru, and this code would probably not do what you want except for this file. The idea is to have a named table, use it as a data source in a named code block that generates the image. Then, make an elisp function that goes to that code block and run it, and set an idle timer to run the elisp function. I have this in my init file: ;; refresh images after running a block (add-hook 'org-babel-after-execute-hook (lambda () (org-display-inline-images nil t))) which refreshes inline images after each execution. This works, but it might take some tinkering to get your idle time ok. 1 second was much too low, 5 seconds is not too bad, although there is a notable lag when the graph is made, and the buffer moves around a bit. there is no error checking for data in the table, so if it crashes the plotting block, you get an error. * "live" graphics in org-mode #+tblname: tbldata | x | y | |-----+-----| | 1 | 1 | | 1 | 0 | | 2 | 4 | | 3 | 5 | | 0.2 | 0.3 | #+RESULTS: make-table-graph #+BEGIN_SRC org [[1, 1], [1, 0], [2, 4], [3, 5], [0.2, 0.3]] [[./live-chart.png]] #+END_SRC * Code #+NAME: make-table-graph #+BEGIN_SRC python :var data=tbldata :results org import matplotlib.pyplot as plt plt.plot([x[0] for x in data], [x[1] for x in data]) plt.savefig('live-chart.png') print data print '[[./live-chart.png]]' #+END_SRC Now, for the elisp part. #+BEGIN_SRC emacs-lisp (defun update-graph () (save-excursion (goto-char (point-min)) (re-search-forward "#\\+NAME: make-table-graph") (forward-line 2) (org-babel-execute-src-block))) (defvar my-timer nil) (setq my-timer (run-with-idle-timer 5 ; idle for this many seconds t ; repeat indefinitely 'update-graph)) #+END_SRC #+RESULTS: : [nil 0 5 0 t update-graph nil idle 0] #+BEGIN_SRC emacs-lisp (cancel-timer my-timer) #+END_SRC Tom writes: > Reading the documentation it is not clear for me if live > charts are supported. > > By live chart I mean having a table data and below that > an inserted image in the buffer which shows the data rendered > from the table, and the image is updated automatically every time > the the table is changed (and, say, emacs is idle for a while). > > So I'm not talking about exporting, but having the live rendered > chart image right in the buffer, > > Can org do this? I don't see any technical obstacles, but > I haven't seen this explicitly mentioned in the docs, that's > why I'm asking. > > > -- ----------------------------------- John Kitchin Professor Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 http://kitchingroup.cheme.cmu.edu