From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: Inline plot with matplotlib Date: Tue, 10 Sep 2013 01:08:43 +0200 Message-ID: <87y575y4n8.fsf@gmx.us> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJAZp-00019C-Ep for emacs-orgmode@gnu.org; Mon, 09 Sep 2013 19:09:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJAZj-0002kk-IK for emacs-orgmode@gnu.org; Mon, 09 Sep 2013 19:09:01 -0400 Received: from plane.gmane.org ([80.91.229.3]:56648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJAZj-0002kU-By for emacs-orgmode@gnu.org; Mon, 09 Sep 2013 19:08:55 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VJAZi-0000gh-EZ for emacs-orgmode@gnu.org; Tue, 10 Sep 2013 01:08:54 +0200 Received: from f053038129.adsl.alicedsl.de ([78.53.38.129]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Sep 2013 01:08:54 +0200 Received: from rasmus by f053038129.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Sep 2013 01:08:54 +0200 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: emacs-orgmode@gnu.org 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.