emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Matplotlib (Python) plots inline
@ 2011-06-06  9:21 Torsten Bronger
  2011-06-06 12:09 ` Pierre de Buyl
  2011-06-06 12:14 ` Eric Schulte
  0 siblings, 2 replies; 5+ messages in thread
From: Torsten Bronger @ 2011-06-06  9:21 UTC (permalink / raw)
  To: emacs-orgmode

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: torsten.bronger@jabber.rwth-aachen.de
                                  or http://bronger-jmp.appspot.com

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

* Re: Matplotlib (Python) plots inline
  2011-06-06  9:21 Matplotlib (Python) plots inline Torsten Bronger
@ 2011-06-06 12:09 ` Pierre de Buyl
  2011-06-09  7:30   ` Torsten Bronger
  2011-06-06 12:14 ` Eric Schulte
  1 sibling, 1 reply; 5+ messages in thread
From: Pierre de Buyl @ 2011-06-06 12:09 UTC (permalink / raw)
  To: Torsten Bronger; +Cc: emacs-orgmode

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: torsten.bronger@jabber.rwth-aachen.de
>                                   or http://bronger-jmp.appspot.com
>
>

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

* Re: Matplotlib (Python) plots inline
  2011-06-06  9:21 Matplotlib (Python) plots inline Torsten Bronger
  2011-06-06 12:09 ` Pierre de Buyl
@ 2011-06-06 12:14 ` Eric Schulte
  2011-06-09  7:29   ` Torsten Bronger
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2011-06-06 12:14 UTC (permalink / raw)
  To: emacs-orgmode

Hi Torsten,

You could try

#+begin_src python :exports results :file /tmp/plot_test.png
  ...
#+end_src

Which should behave as desired.

Best -- Eric

Torsten Bronger <bronger@physik.rwth-aachen.de> writes:

> 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
>
> #+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]]
>
> 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.

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

* Re: Matplotlib (Python) plots inline
  2011-06-06 12:14 ` Eric Schulte
@ 2011-06-09  7:29   ` Torsten Bronger
  0 siblings, 0 replies; 5+ messages in thread
From: Torsten Bronger @ 2011-06-09  7:29 UTC (permalink / raw)
  To: emacs-orgmode

Hallöchen!

Eric Schulte writes:

> You could try
> #+begin_src python :exports results :file /tmp/plot_test.png
>   ...
> #+end_src
> Which should behave as desired.

Thank you, I think this is how I'll do it.  Exporting is not so
important to me (at least, not yet).

Tschö,
Torsten.

-- 
Torsten Bronger    Jabber ID: torsten.bronger@jabber.rwth-aachen.de
                                  or http://bronger-jmp.appspot.com

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

* Re: Matplotlib (Python) plots inline
  2011-06-06 12:09 ` Pierre de Buyl
@ 2011-06-09  7:30   ` Torsten Bronger
  0 siblings, 0 replies; 5+ messages in thread
From: Torsten Bronger @ 2011-06-09  7:30 UTC (permalink / raw)
  To: emacs-orgmode

Hallöchen!

Pierre de Buyl writes:

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

Thanks also for your answer, however, one should write

    print "[" + "[/tmp/plot_test.png]]"

or something like this in order to prevent the string literal from
being substituted by the bitmap.

Tschö,
Torsten.

-- 
Torsten Bronger    Jabber ID: torsten.bronger@jabber.rwth-aachen.de
                                  or http://bronger-jmp.appspot.com

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

end of thread, other threads:[~2011-06-09  7:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-06  9:21 Matplotlib (Python) plots inline Torsten Bronger
2011-06-06 12:09 ` Pierre de Buyl
2011-06-09  7:30   ` Torsten Bronger
2011-06-06 12:14 ` Eric Schulte
2011-06-09  7:29   ` Torsten Bronger

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).