emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dan Davison <davison@stats.ox.ac.uk>
To: Johan Ekh <ekh.johan@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Plotting date on xaxis
Date: Tue, 23 Feb 2010 12:15:44 -0500	[thread overview]
Message-ID: <87vddnzxdr.fsf@stats.ox.ac.uk> (raw)
In-Reply-To: <417457b51002230827w555d345dg98fbbea5c0091a36@mail.gmail.com> (Johan Ekh's message of "Tue, 23 Feb 2010 17:27:13 +0100")

Johan Ekh <ekh.johan@gmail.com> writes:

> Thanks guys,
> the babel version worked perfect so I didn't try the other one thanks!
> Would it be possible to use python and matplotlib with babel instead of
> gnuplot?
> If so, could you just indicate how such a src code block would look like?

Hi Johan,

I've never used matplotlib, but here's a start. Firstly, one thing I
notice is that org-babel-python currently doesn't like the column names
on the table (I'll add it to our TODO list). So if we make a table like
this, without the header:

#+results: my-table-nohdr
| 2010-02-21 | 95.0 |
| 2010-02-22 | 93.0 |
| 2010-02-23 | 92.0 |
| 2010-02-24 | 91.5 |
| 2010-02-25 | 91.0 |
| 2010-02-26 | 92.0 |

Then pass the data into python and have a look at what we've got:

#+begin_src python :var data=my-table-nohdr :results output
print str(data)
#+end_src

#+results:
: [['2010-02-21', 95.0], ['2010-02-22', 93.0], ['2010-02-23', 92.0], ['2010-02-24', 91.5], ['2010-02-25', 91.0], ['2010-02-26', 92.0]]

So if you know how to use matplotlib to create your plot using that list
of lists, then you should be set. To get output to file you will need to
use something like :file pyplot.png, *and* arrange that your code writes
the graphical output to pyplot.png. A link to pyplot.png will be
inserted in the org buffer.

Given my ignorance of gnuplot and matplotlib, I would use R. Unlike
python, but like gnuplot, the graphical output is automatically sent to
the specified file, without having to explicitly tell R to so so:

#+begin_src R :var d=my-table :file R-plot.png
  plot(as.Date(d$Date), d$Kg, ylab="Kg", type="b")
#+end_src

#+results:
[[file:R-plot.png]]

Dan

>
> Babel seems super cool!
>
> /Johan
>
> On Tue, Feb 23, 2010 at 3:47 PM, Eric Schulte <schulte.eric@gmail.com> wrote:
>
>     Hi Johan,
>
>     You could try plotting your table using standard org-mode date formats
>     which org-plot will understand without any need to specify a timefmt
>     string.
>
>     #+PLOT: title:"Weight" ind:1 deps:(2) type:2d with:linespo set:"xdata time"
>     set:"yrange [90:]"
>     | Date             |   Kg |
>     |------------------+------|
>     | <2010-02-21 Sun> | 95.0 |
>     | <2010-02-22 Mon> | 93.0 |
>     | <2010-02-23 Tue> | 92.0 |
>     | <2010-02-24 Wed> | 91.5 |
>     | <2010-02-25 Thu> | 91.0 |
>     | <2010-02-26 Fri> | 92.0 |
>
>     Alternatively if you want more control over your plots and more direct
>     access to gnuplot you can use org-babel to pass your table directly to
>     gnuplot as follows.
>
>     #+results: my-table
>     |       Date |   Kg |
>     |------------+------|
>     | 2010-02-21 | 95.0 |
>     | 2010-02-22 | 93.0 |
>     | 2010-02-23 | 92.0 |
>     | 2010-02-24 | 91.5 |
>     | 2010-02-25 | 91.0 |
>     | 2010-02-26 | 92.0 |
>
>     #+begin_src gnuplot :var data=my-table
>      set xdata time
>      set timefmt '%Y-%m-%d'
>      set yrange [90:]
>      plot data using 1:2 with linespoints title 'Kg'
>     #+end_src
>
>     Best -- Eric
>
>     Johan Ekh <ekh.johan@gmail.com> writes:
>
>     > Hi all,
>     > I try to plot a table looking like this
>     >
>     >      |       Date    |   Kg |
>     >      |-----------------+--------|
>     >      | 2010-02-21 | 95.0 |
>     >      | 2010-02-22 | 93.0 |
>     >      | 2010-02-23 | 92.0 |
>     >      | 2010-02-24 | 91.5 |
>     >      | 2010-02-25 | 91.0 |
>     >      | 2010-02-29 | 92.0 |
>     >      |                  |        |
>     >
>     > with the dates on the xaxis using
>     >
>     > #+PLOT: title:"Weight" ind:1 deps:(2) type:2d with:linespo set:"xdata
>     time" timefmt:%Y-%m-%d
>     > set:"yrange [90:]"
>     >
>     > but no plot is generated. If I remove <set:"xdata time">, the plot is
>     generated but without
>     > interpreting the dates as dates.
>     >
>     > Can anyone see what I do wrong?
>     >
>     > Thanks in advance,
>     >
>     > Johan
>     >
>     > _______________________________________________
>     > Emacs-orgmode mailing list
>     > Please use `Reply All' to send replies to the list.
>     > Emacs-orgmode@gnu.org
>     > http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2010-02-23 17:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-22 18:31 Plotting date on xaxis Johan Ekh
2010-02-23  9:52 ` Eric S Fraga
2010-02-23 14:47 ` Eric Schulte
2010-02-23 16:27   ` Johan Ekh
2010-02-23 17:15     ` Dan Davison [this message]
2010-02-23 17:33       ` Eric Schulte
2010-02-23 22:52   ` Eric S Fraga
2010-02-24  0:05     ` Eric Schulte
2010-02-24  8:07       ` Eric S Fraga
2010-02-25 17:44         ` Eric Schulte
2010-02-25 20:11           ` Eric S Fraga
2010-02-26 15:09             ` Johan Ekh
2010-05-15 13:47 ` Ivan Vilata i Balaguer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vddnzxdr.fsf@stats.ox.ac.uk \
    --to=davison@stats.ox.ac.uk \
    --cc=ekh.johan@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).