From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pierre de Buyl Subject: Re: Matplotlib (Python) plots inline Date: Mon, 6 Jun 2011 08:09:18 -0400 Message-ID: References: <87fwnn71t9.fsf@physik.rwth-aachen.de> Mime-Version: 1.0 (Apple Message framework v753.1) Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:53638) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTYce-0002R7-9b for emacs-orgmode@gnu.org; Mon, 06 Jun 2011 08:09:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTYca-0006ie-FK for emacs-orgmode@gnu.org; Mon, 06 Jun 2011 08:09:31 -0400 Received: from mxin.ulb.ac.be ([164.15.128.112]:48821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTYcZ-0006iN-Sc for emacs-orgmode@gnu.org; Mon, 06 Jun 2011 08:09:28 -0400 In-Reply-To: <87fwnn71t9.fsf@physik.rwth-aachen.de> 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: Torsten Bronger Cc: emacs-orgmode@gnu.org Hello, I have success with the following: #+begin_src python :results output raw :exports results import numpy, matplotlib, matplotlib.pyplot figure =3D matplotlib.pyplot.figure() axes =3D figure.add_subplot(111, title=3Du"Hello", xlabel=3D"x", =20 ylabel=3D"y") x =3D numpy.arange(-10, 10, 0.1) axes.plot(x, x**2) figure.savefig("/tmp/plot_test.png") figure.clf() print "[[/tmp/plot_test.png]]" #+end_src You get only the figure as a result, and not the code. This method executes the code at each export. The alternative is to =20 set ":exports none" , to execute with C-c C-c and then to delete the =20 "+results:" line so that the result is exported. Pierre Le 6 juin 11 =E0 05:21, Torsten Bronger a =E9crit : > Hall=F6chen! > > I wonder what is the best way to include plots generated from Python > code into my notes. I found a way but maybe there's a better one. > > What I do is > > --8<---------------cut here---------------start------------->8--- > #+begin_src python > import numpy, matplotlib, matplotlib.pyplot > figure =3D matplotlib.pyplot.figure() > axes =3D figure.add_subplot(111, title=3Du"Hello", xlabel=3D"x", =20 > ylabel=3D"y") > x =3D numpy.arange(-10, 10, 0.1) > axes.plot(x, x**2) > figure.savefig("/tmp/plot_test.png") > figure.clf() > #+end_src > > #+results: > : None > > [[/tmp/plot_test.png]] > --8<---------------cut here---------------end--------------->8--- > > However, it is a little bit cumbersome. Is there an easier way to > define code (possibly with boilerplate), and let it be replaced with > the graphics file it produces? > > Tsch=F6, > Torsten. > > --=20 > Torsten Bronger Jabber ID: torsten.bronger@jabber.rwth-aachen.de > or http://bronger-jmp.appspot.com > >