emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Matplotlib (Python) plots inline


From: Pierre de Buyl
Subject: Re: [O] Matplotlib (Python) plots inline
Date: Mon, 6 Jun 2011 08:09:18 -0400

Hello,

I have success with the following:
#+begin_src python :results output raw :exports results
  import numpy, matplotlib, matplotlib.pyplot
  figure = matplotlib.pyplot.figure()
axes = figure.add_subplot(111, title=u"Hello", xlabel="x", ylabel="y")
  x = 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 set ":exports none" , to execute with C-c C-c and then to delete the "+results:" line so that the result is exported.

Pierre

Le 6 juin 11 à 05:21, Torsten Bronger a écrit :

Hallöchen!

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 = matplotlib.pyplot.figure()
axes = figure.add_subplot(111, title=u"Hello", xlabel="x", ylabel="y")
  x = 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ö,
Torsten.

--
Torsten Bronger    Jabber ID: address@hidden
                                  or http://bronger-jmp.appspot.com






reply via email to

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