From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johan Ekh Subject: Re: Inline plot with matplotlib Date: Wed, 11 Sep 2013 16:47:47 +0200 Message-ID: References: <87y575y4n8.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0158c6f06e2c6a04e61cb488 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJlhx-0003aD-Li for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 10:47:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJlhs-0000av-LX for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 10:47:53 -0400 Received: from mail-oa0-x22e.google.com ([2607:f8b0:4003:c02::22e]:43332) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJlhs-0000ae-EW for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 10:47:48 -0400 Received: by mail-oa0-f46.google.com with SMTP id o20so9368042oag.33 for ; Wed, 11 Sep 2013 07:47:47 -0700 (PDT) In-Reply-To: <87y575y4n8.fsf@gmx.us> 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: Rasmus Cc: "emacs-orgmode@gnu.org" --089e0158c6f06e2c6a04e61cb488 Content-Type: text/plain; charset=ISO-8859-1 Thank you! This works! /Johan On Tue, Sep 10, 2013 at 1:08 AM, Rasmus wrote: > Johan Ekh writes: > > > Hi all, > > I would like to create a plot with matplotlib and have it exported to a > > beamer presentation without storing the plot in a file. Is that possible? > > I guess you'd want to plot is as a pgf file, whether real of > 'virtual'. You could send the result to STDOUT but it may take a bit > more effort. Also, a simple test with sys.stdout says the pgf backend > doesn't support stdout. . . > > If *printing* to a pgf file everything works out of the box in recent > versions of Org. > > > Can someone point me to an example or a good starting point? > > http://matplotlib.org/users/pgf.html > > Here's an example of a simple plot. > > #+TITLE: =matplotlib= and =pgf= > #+LATEX_HEADER: \usepackage{pgf} > #+NAME:spectrum > #+BEGIN_SRC python :var OUT="test.pgf" :exports results :results value file > import matplotlib as mpl > pgf_with_pdflatex = { > "pgf.texsystem": "pdflatex", > "text.usetex": True, > 'pgf.rcfonts': False, > 'font.size': 9, > 'fond.family': 'serif', > "pgf.preamble": [ > r"\usepackage[utf8]{inputenc}", > r"\usepackage[T1]{fontenc}"]} > mpl.rcParams.update(pgf_with_pdflatex) > import matplotlib.pyplot as plt > from numpy import pi, cos, linspace > s1, t1, t2 = 1, .8, .2 > s = lambda w: s1 / (2 * pi) * (1 + t1 ** 1 + t2 ** 2 + (1 + t2) * 2 * t1 > * cos(w) + 2 * t2 * cos(4 * w)) > x = linspace(0, pi, 1000) > plt.figure(figsize=(4,1.5)) > plt.plot(x, s(x)) > plt.xlim( 0, pi) > plt.xlabel("$\\omega$") > plt.ylabel("Spectrum") > plt.tight_layout(0) > plt.savefig(OUT, format = 'pgf') > return(OUT) > #+END_SRC > > #+RESULTS: spectrum > [[file:test.pgf]] > > > > > -- > . . . The proofs are technical in nature and provides no real > understanding. > > > > > > --089e0158c6f06e2c6a04e61cb488 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you! This works!
/Johan


On Tue, Sep 10, 20= 13 at 1:08 AM, Rasmus <rasmus@gmx.us> wrote:
Johan Ekh <ekh.johan@gmail.com> writes:

> Hi all,
> I would like to create a plot with matplotlib and have it exported to = a
> beamer presentation without storing the plot in a file. Is that possib= le?

I guess you'd want to plot is as a pgf file, whether real of
'virtual'. =A0You could send the result to STDOUT but it may take a= bit
more effort. =A0Also, a simple test with sys.stdout says the pgf backend doesn't support stdout. . .

If *printing* to a pgf file everything works out of the box in recent
versions of Org.

> Can someone point me to an example or a good starting point?

=A0 http://matplotlib.org/users/pgf.html

Here's an example of a simple plot.

#+TITLE: =3Dmatplotlib=3D and =3Dpgf=3D
#+LATEX_HEADER: \usepackage{pgf}
#+NAME:spectrum
#+BEGIN_SRC python :var OUT=3D"test.pgf" :exports results :result= s value file
=A0 import matplotlib as mpl
=A0 pgf_with_pdflatex =3D {
=A0 =A0 =A0 "pgf.texsystem": "pdflatex",
=A0 =A0 =A0 "text.usetex": True,
=A0 =A0 =A0 'pgf.rcfonts': False,
=A0 =A0 =A0 'font.size': 9,
=A0 =A0 =A0 'fond.family': 'serif',
=A0 =A0 =A0 "pgf.preamble": [
=A0 =A0 =A0 =A0 =A0 r"\usepackage[utf8]{inputenc}",
=A0 =A0 =A0 =A0 =A0 r"\usepackage[T1]{fontenc}"]}
=A0 mpl.rcParams.update(pgf_with_pdflatex)
=A0 import matplotlib.pyplot as plt
=A0 from numpy import pi, cos, linspace
=A0 s1, t1, t2 =3D 1, .8, .2
=A0 s =3D lambda w: s1 / (2 * pi) * (1 + t1 ** 1 + t2 ** 2 + (1 + t2) * 2 *= t1 * cos(w) + 2 * t2 * cos(4 * w))
=A0 x =3D linspace(0, pi, 1000)
=A0 plt.figure(figsize=3D(4,1.5))
=A0 plt.plot(x, s(x))
=A0 plt.xlim( 0, pi)
=A0 plt.xlabel("$\\omega$")
=A0 plt.ylabel("Spectrum")
=A0 plt.tight_layout(0)
=A0 plt.savefig(OUT, format =3D 'pgf')
=A0 return(OUT)
#+END_SRC

#+RESULTS: spectrum
[[file:test.pgf]]




--
. . . The proofs are technical in nature and provides no real understanding= .






--089e0158c6f06e2c6a04e61cb488--