<TeXmacs|1.99.2>

<style|tmdoc>

<\body>
  <tmdoc-title|Some examples>

  <\session|python|default>
    <\output>
      Python plugin for Python. Please see the documentation in
      Help-\<gtr\>plugins-\<gtr\>Python
    </output>

    <\unfolded-io>
      \<gtr\>\<gtr\>\<gtr\>\ 
    <|unfolded-io>
      #This is a comment

      for i in range(1):

      \ \ \ for j in range(1):

      \ \ \ \ \ \ \ print i,j

      \ \ \ print "*"#Another comment

      print "#"
    <|unfolded-io>
      0 0

      *

      #
    </unfolded-io>

    <\input>
      \<gtr\>\<gtr\>\<gtr\>\ 
    <|input>
      a=5
    </input>

    <\unfolded-io>
      \<gtr\>\<gtr\>\<gtr\>\ 
    <|unfolded-io>
      print a+5
    <|unfolded-io>
      10
    </unfolded-io>

    <\input>
      \<gtr\>\<gtr\>\<gtr\>\ 
    <|input>
      \;
    </input>
  </session>

  <paragraph|An example using <python|matplotlib>>

  For the following example you'll need <python|matplotlib> and
  <python|numpy> installed in your system.

  <\session|python|default>
    <\input>
      \<gtr\>\<gtr\>\<gtr\>\ 
    <|input>
      import matplotlib as mpl

      mpl.use('PS')

      import matplotlib.pyplot as pl

      import numpy as np

      x = np.linspace(0,3)

      pl.plot(x, np.sin(2*x))

      fig = pl.gcf()
    </input>

    <\unfolded-io>
      \<gtr\>\<gtr\>\<gtr\>\ 
    <|unfolded-io>
      ps_out(fig)
    <|unfolded-io>
      <image|<tuple|<#[encoded data, 24440 characters]>|ps>|0.7par|||>

      \;
    </unfolded-io>
  </session>

  Using <menu|Insert|Executable|Python> it is possible to embed images into
  your document without having sessions. Assuming you've run the code above,
  pressing <key|S-return> \ in the executable environment in the next figure
  will compile the code in it and display the graph:

  <big-figure|<\script-input|python|default>
    # Try me! Press Shift+return

    pl.clf() # Clear the last figure

    pl.plot(x, x + np.sin(4*x))

    ps_out(fig)
  </script-input|<image|<tuple|<#[encoded data, 26178 characters]>|ps>|0.7par|||>>|A
  graph with the code ``behind''>

  <tmdoc-copyright|2004, 2014|Adrián Soto|Miguel de Benito Delgado>

  <tmdoc-license|Permission is granted to copy, distribute and/or modify this
  document under the terms of the GNU Free Documentation License, Version 1.1
  or any later version published by the Free Software Foundation; with no
  Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
  Texts. A copy of the license is included in the section entitled "GNU Free
  Documentation License".>
</body>

<\initial>
  <\collection>
    <associate|page-type|letter>
    <associate|par-hyphen|normal>
  </collection>
</initial>