all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Inline plot with matplotlib
@ 2013-09-09 22:27 Johan Ekh
  2013-09-09 23:05 ` Eric Schulte
  2013-09-09 23:08 ` Rasmus
  0 siblings, 2 replies; 4+ messages in thread
From: Johan Ekh @ 2013-09-09 22:27 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 227 bytes --]

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?
Can someone point me to an example or a good starting point?

BR / Johan

[-- Attachment #2: Type: text/html, Size: 284 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Inline plot with matplotlib
  2013-09-09 22:27 Inline plot with matplotlib Johan Ekh
@ 2013-09-09 23:05 ` Eric Schulte
  2013-09-09 23:08 ` Rasmus
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2013-09-09 23:05 UTC (permalink / raw)
  To: Johan Ekh; +Cc: emacs-orgmode@gnu.org

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 possible?
> Can someone point me to an example or a good starting point?
>
> BR / Johan

If matplotlib supports tikz or raw tex output formats, you could use a
python code block, e.g., something like the following.

    #+begin_src python :results latex
      # Python code to print latex code for a graph
    #+end_src

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Inline plot with matplotlib
  2013-09-09 22:27 Inline plot with matplotlib Johan Ekh
  2013-09-09 23:05 ` Eric Schulte
@ 2013-09-09 23:08 ` Rasmus
  2013-09-11 14:47   ` Johan Ekh
  1 sibling, 1 reply; 4+ messages in thread
From: Rasmus @ 2013-09-09 23:08 UTC (permalink / raw)
  To: emacs-orgmode

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 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Inline plot with matplotlib
  2013-09-09 23:08 ` Rasmus
@ 2013-09-11 14:47   ` Johan Ekh
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Ekh @ 2013-09-11 14:47 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1931 bytes --]

Thank you! This works!
/Johan


On Tue, Sep 10, 2013 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 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.
>
>
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-11 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-09 22:27 Inline plot with matplotlib Johan Ekh
2013-09-09 23:05 ` Eric Schulte
2013-09-09 23:08 ` Rasmus
2013-09-11 14:47   ` Johan Ekh

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.