From mboxrd@z Thu Jan 1 00:00:00 1970 From: William =?UTF-8?B?TMOJQ0hFTExF?= Subject: Re: python/babel inline images Date: Tue, 05 Jun 2012 18:34:46 -0400 Message-ID: <87ehpt8k1l.wl%william.lechelle@ens-lyon.fr> References: <87pq9egifm.fsf@bye.fritz.box> <874nqp9580.fsf@gmx.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:49399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sc2L4-0004un-Ui for emacs-orgmode@gnu.org; Tue, 05 Jun 2012 18:35:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sc2Kz-0000Jc-3l for emacs-orgmode@gnu.org; Tue, 05 Jun 2012 18:34:58 -0400 Received: from jabiru.ens-lyon.fr ([140.77.51.2]:32841) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sc2Ky-0000JG-T0 for emacs-orgmode@gnu.org; Tue, 05 Jun 2012 18:34:53 -0400 In-Reply-To: <874nqp9580.fsf@gmx.com> 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: Eric Schulte Cc: emacs-orgmode@gnu.org At Tue, 05 Jun 2012 08:57:19 -0600, Eric Schulte wrote: >=20 > henry atting writes: >=20 > > 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 =3D [] > > y =3D [] > > csv_reader =3D 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=3Dr'exp', color=3D'green') > > plot.legend(loc=3D'lower right') > > plot.savefig("exp_csv.svg") > > #+end_src > > > > It tried different combinations of `:exports results', `:results > > file', `:file filename' >=20 > 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 expecte= d > for me. >=20 > #+begin_src sh > pwd > #+end_src >=20 > If you want to explicitly pass the current directory to your code block > as an argument, you could try something like the following >=20 > #+begin_src python :var mydir=3D(file-name-directory (buffer-file-name)= ) > return mydir > #+end_src I guess if it's a paths' problem, the python equivalent would be os.getcw= d(), 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-bab= el 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.sa= vefig 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=E2=80=AF? #+begin_src python :results output file <> path =3D "exp_csv.svg" plot.savefig(path) print path #+end_src HTH