From: "William LÉCHELLE" <william.lechelle@ens-lyon.fr>
To: Eric Schulte <eric.schulte@gmx.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: python/babel inline images
Date: Tue, 05 Jun 2012 18:34:46 -0400 [thread overview]
Message-ID: <87ehpt8k1l.wl%william.lechelle@ens-lyon.fr> (raw)
In-Reply-To: <874nqp9580.fsf@gmx.com>
At Tue, 05 Jun 2012 08:57:19 -0600,
Eric Schulte wrote:
>
> henry atting <nsmp_06@online.de> writes:
>
> > Hi,
> >
> > I do not succeed in generating an inline image as a result of a
> > python code block. The code itself works, C-c C-c generates the
> > according picture, but only in my home directory. The code block:
> >
> > -*- org-babel-python-command: "python3" -*-
> > #+begin_src python
> > import csv
> > import matplotlib.pyplot as plot
> > x = []
> > y = []
> > csv_reader = csv.reader(open('csv_data.csv'))
> > for line in csv_reader:
> > x.append(int(line[0]))
> > y.append(float(line[1]))
> > plot.plot(x, y, label=r'exp', color='green')
> > plot.legend(loc='lower right')
> > plot.savefig("exp_csv.svg")
> > #+end_src
> >
> > It tried different combinations of `:exports results', `:results
> > file', `:file filename'
>
> I'm not python expert, but the code block should be run in your current
> directory, e.g., the following outputs the current working path expected
> for me.
>
> #+begin_src sh
> pwd
> #+end_src
>
> If you want to explicitly pass the current directory to your code block
> as an argument, you could try something like the following
>
> #+begin_src python :var mydir=(file-name-directory (buffer-file-name))
> return mydir
> #+end_src
I guess if it's a paths' problem, the python equivalent would be os.getcwd(),
from the os module, and a solution to have the picture in the right place
could be os.chdir(path) (or maybe plot.savefig can take a full path as an
argument), but I think the OP (and I'm very interested too) wants org-babel to
manage the python output somehow to inline the image automatically.
I don't see that possible, because I don't think the "results" of plot.savefig
is the value of the image, but rather an i/o operation somehow (and I may well
be wrong) (and nothing goes to stdout). But maybe to output a link could do ?
#+begin_src python :results output file
<<stuff>>
path = "exp_csv.svg"
plot.savefig(path)
print path
#+end_src
HTH
next prev parent reply other threads:[~2012-06-05 22:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-05 10:30 python/babel inline images henry atting
2012-06-05 12:46 ` Brett Viren
2012-06-05 14:57 ` Eric Schulte
2012-06-05 22:34 ` William LÉCHELLE [this message]
2012-06-06 15:19 ` henry atting
2012-06-06 19:16 ` Mikhail Titov
2012-06-06 19:25 ` Eric Schulte
2012-06-06 19:32 ` Mikhail Titov
2012-06-07 8:43 ` henry atting
2012-06-07 15:09 ` Mikhail Titov
2012-06-06 0:59 ` Mikhail Titov
2012-06-06 5:19 ` Eric Schulte
2012-06-06 17:41 ` [babel] session initialization (was RE: python/babel inline images) Mikhail Titov
2012-06-06 19:01 ` Eric Schulte
2012-06-06 19:41 ` Mikhail Titov
2012-06-06 23:06 ` Mikhail Titov
2012-06-07 22:32 ` Mikhail Titov
2012-06-07 22:44 ` Eric Schulte
2012-06-07 23:02 ` Mikhail Titov
2012-06-08 1:56 ` Mikhail Titov
2012-06-08 2:18 ` Eric Schulte
2012-06-07 22:48 ` Eric Schulte
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=87ehpt8k1l.wl%william.lechelle@ens-lyon.fr \
--to=william.lechelle@ens-lyon.fr \
--cc=emacs-orgmode@gnu.org \
--cc=eric.schulte@gmx.com \
/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).