[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Inline plot with matplotlib

From: Johan Ekh
Subject: Re: [O] Inline plot with matplotlib
Date: Wed, 11 Sep 2013 16:47:47 +0200

Thank you! This works!

On Tue, Sep 10, 2013 at 1:08 AM, Rasmus <address@hidden> wrote:
Johan Ekh <address@hidden> 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?


Here's an example of a simple plot.

#+TITLE: =matplotlib= and =pgf=
#+LATEX_HEADER: \usepackage{pgf}
#+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": [
  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.plot(x, s(x))
  plt.xlim( 0, pi)
  plt.savefig(OUT, format = 'pgf')

#+RESULTS: spectrum

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]