[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Can org show live charts?

From: John Kitchin
Subject: Re: [O] Can org show live charts?
Date: Tue, 21 Oct 2014 19:15:59 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (darwin)

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
[[1, 1], [1, 0], [2, 4], [3, 5], [0.2, 0.3]]

* 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])
print data
print '[[./live-chart.png]]'

Now, for the elisp part.

#+BEGIN_SRC emacs-lisp
(defun update-graph ()
    (goto-char (point-min))
    (re-search-forward "#\\+NAME: make-table-graph")
    (forward-line 2)

(defvar my-timer nil)

(setq my-timer (run-with-idle-timer
                5 ; idle for this many seconds
                t ; repeat indefinitely

: [nil 0 5 0 t update-graph nil idle 0]

#+BEGIN_SRC emacs-lisp
(cancel-timer my-timer)

Tom <address@hidden> 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
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213

reply via email to

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