From fd4dd9630df3daa22ab88eac4a7ed08a4e9be212 2013-02-08 19:13:25 From: damianavila Date: 2013-02-08 19:13:25 Subject: [PATCH] A new implementation of reveal converter with jinja templates. --- diff --git a/converters/transformers.py b/converters/transformers.py index 770700b..825bb25 100755 --- a/converters/transformers.py +++ b/converters/transformers.py @@ -139,9 +139,9 @@ class ExtractFigureTransformer(ActivatableTransformer): """Create a new figure file in the given format. """ - tplf = self.figname_format_map.get(fmt,self.default_key_tpl) + tplf = self.figname_format_map.get(fmt,self.default_key_tpl) tplk = self.key_format_map.get(fmt,self.default_key_tpl) - + # option to pass the hash as data ? figname = tplf.format(count=count, ext=self._get_ext(fmt)) key = tplk.format(count=count, ext=self._get_ext(fmt)) @@ -167,105 +167,20 @@ class ExtractFigureTransformer(ActivatableTransformer): class RevealHelpTransformer(ConfigurableTransformers): - section_open = False - subsection_open = False - fragment_open = False - - def open_subsection(self): - self.subsection_open = True - return True - - def open_section(self): - self.section_open = True - return True - - def open_fragment(self): - self.fragment_open = True - return True - - # could probaly write those maybe_close/open - # with a function functor - def maybe_close_section(self): - """return True is already open, false otherwise - and change state to close - """ - if self.section_open : - self.section_open = False - return True - else : - return False - - def maybe_open_section(self): - """return True is already open, false otherwise - and change state to close - """ - if not self.section_open : - self.section_open = True - return True - else : - return False - - def maybe_open_subsection(self): - """return True is already open, false otherwise - and change state to close - """ - if not self.subsection_open : - self.subsection_open = True - return True - else : - return False - - def maybe_close_subsection(self): - """return True is already open, false otherwise - and change state to close - """ - if self.subsection_open : - self.subsection_open = False - return True - else : - return False - - def maybe_close_fragment(self): - """return True is already open, false otherwise - and change state to close - """ - if self.fragment_open : - self.fragment_open = False - return True - else : - return False - - def cell_transform(self, cell, other, count): - ctype = cell.metadata.get('slideshow', {}).get('slide_type', None) - if ctype in [None, '-'] : - cell.metadata.slideshow = {} - cell.metadata.slideshow['slide_type'] = None - elif ctype == 'fragment': - cell.metadata.slideshow.close_fragment = self.maybe_close_fragment() - cell.metadata.slideshow.close_subsection = False - cell.metadata.slideshow.close_section = False - - cell.metadata.slideshow.open_section = self.maybe_open_section() - cell.metadata.slideshow.open_subsection = self.maybe_open_subsection() - cell.metadata.slideshow.open_fragment = self.open_fragment() - - elif ctype == 'subslide': - cell.metadata.slideshow.close_fragment = self.maybe_close_fragment() - cell.metadata.slideshow.close_subsection = self.maybe_close_subsection() - cell.metadata.slideshow.close_section = False - - cell.metadata.slideshow.open_section = self.maybe_open_section() - cell.metadata.slideshow.open_subsection = self.open_subsection() - cell.metadata.slideshow.open_fragment = False - elif ctype == 'slide': - cell.metadata.slideshow.close_fragment = self.maybe_close_fragment() - cell.metadata.slideshow.close_subsection = self.maybe_close_subsection() - cell.metadata.slideshow.close_section = self.maybe_close_section() - - cell.metadata.slideshow.open_section = self.open_section() - cell.metadata.slideshow.open_subsection = self.open_subsection() - cell.metadata.slideshow.open_fragment = False - return cell, other + def __call__(self, nb, other): + try : + for worksheet in nb.worksheets : + for i, cell in enumerate(worksheet.cells): + cell.metadata.slide_type = cell.metadata.get('slideshow', {}).get('slide_type', None) + if cell.metadata.slide_type is None: + cell.metadata.slide_type = '-' + if cell.metadata.slide_type in ['slide']: + worksheet.cells[i - 1].metadata.slide_helper = 'slide_end' + if cell.metadata.slide_type in ['subslide']: + worksheet.cells[i - 1].metadata.slide_helper = 'subslide_end' + return nb, other + except NotImplementedError as error : + raise NotImplementedError('should be implemented by subclass') class CSSHtmlHeaderTransformer(ActivatableTransformer): diff --git a/templates/reveal.tpl b/templates/reveal.tpl index c036815..3ab59bb 100644 --- a/templates/reveal.tpl +++ b/templates/reveal.tpl @@ -1,85 +1,8 @@ -{%- extends 'basichtml.tpl' -%} +{%- extends 'slides.tpl' -%} -{% block any_cell -%} - -{% if cell.metadata.slideshow.close_fragment %} - -{% endif %} -{% if cell.metadata.slideshow.close_subsection %} - -{% endif %} -{% if cell.metadata.slideshow.close_section %} - -{% endif %} - -{% if cell.metadata.slideshow.open_section %} -
-{%- endif %} -{% if cell.metadata.slideshow.open_subsection %} -
-{%- endif %} -{% if cell.metadata.slideshow.open_fragment %} -
-{% endif %} -{% if cell.metadata.slideshow.slide_type in ['notes'] %} - -{% elif cell.metadata.slideshow.slide_type not in ['skip'] %} -{{ super() }} -{% endif %} - -{% endblock %} - - -{% block body %} - -
-{{ super() }} -
-
- - - - - - - - - - -{% endblock body %} - - - - -{% block header %} +{% block header %} + @@ -147,4 +70,65 @@ div.output_prompt { margin: 5px 5px 0 -5px; } -{% endblock %} + +{% endblock header%} + + +{% block body %} + +
+ +{{ super() }} + +
+ + +
+ + + + + +
+ + + + + + + + + + + +{% endblock body %} + +{% block footer %} + +{% endblock footer %} \ No newline at end of file diff --git a/templates/reveal_cells.tpl b/templates/reveal_cells.tpl new file mode 100644 index 0000000..5f84a41 --- /dev/null +++ b/templates/reveal_cells.tpl @@ -0,0 +1,21 @@ +{%- extends 'basichtml.tpl' -%} + + + +{%- block any_cell scoped -%} +{%- if cell.metadata.slide_type in ['-', 'slide', 'subslide'] -%} + {{ super() }} +{%- elif cell.metadata.slide_type in ['skip'] -%} +
+ {{ super() }} +
+{%- elif cell.metadata.slide_type in ['notes'] -%} + +{%- elif cell.metadata.slide_type in ['fragment'] -%} +
+ {{ super() }} +
+{%- endif -%} +{%- endblock any_cell -%} diff --git a/templates/slides.tpl b/templates/slides.tpl new file mode 100644 index 0000000..b33084c --- /dev/null +++ b/templates/slides.tpl @@ -0,0 +1,17 @@ +{%- extends 'subslides.tpl' -%} + + + +{%- block any_cell scoped -%} +{%- if cell.metadata.slide_type in ['slide'] -%} +
+
+{%- endif -%} + +{{ super() }} + +{%- if cell.metadata.slide_helper in ['slide_end'] -%} +
+
+{%- endif -%} +{%- endblock any_cell -%} diff --git a/templates/subslides.tpl b/templates/subslides.tpl new file mode 100644 index 0000000..c4181db --- /dev/null +++ b/templates/subslides.tpl @@ -0,0 +1,15 @@ +{%- extends 'reveal_cells.tpl' -%} + + + +{%- block any_cell scoped -%} +{%- if cell.metadata.slide_type in ['subslide'] -%} +
+{%- endif -%} + +{{ super() }} + +{%- if cell.metadata.slide_helper in ['subslide_end'] -%} +
+{%- endif -%} +{%- endblock any_cell -%} diff --git a/reveal.orig.ipynb b/tests/ipynbref/reveal.orig.ipynb similarity index 100% rename from reveal.orig.ipynb rename to tests/ipynbref/reveal.orig.ipynb diff --git a/tests/ipynbref/reveal.orig_slides.html b/tests/ipynbref/reveal.orig_slides.html new file mode 100644 index 0000000..061b3c3 --- /dev/null +++ b/tests/ipynbref/reveal.orig_slides.html @@ -0,0 +1,4001 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+

A brief tour of the IPython notebook

+

This document will give you a brief tour of the capabilities of the IPython notebook.
+You can view its contents by scrolling around, or execute each cell by typing Shift-Enter. +After you conclude this brief high-level tour, you should read the accompanying notebook +titled 01_notebook_introduction, which takes a more step-by-step approach to the features of the +system.
+

+

The rest of the notebooks in this directory illustrate various other aspects and +capabilities of the IPython notebook; some of them may require additional libraries to be executed.

+
+
+
+
+
+
In [1]:
+
+
pwd
+
+ +
+
+
+
+
+
Out[1]:
+
+
+
+
+ +
u'/Users/minrk/dev/ip/mine/docs/examples/notebooks'
+
+
+
+
+
+
+
+
In [2]:
+
+
ls
+
+ +
+
+
+
+
+
+
+
+
+
+
00_notebook_tour.ipynb          callbacks.ipynb                 python-logo.svg
+01_notebook_introduction.ipynb  cython_extension.ipynb          rmagic_extension.ipynb
+Animations_and_Progress.ipynb   display_protocol.ipynb          sympy.ipynb
+Capturing Output.ipynb          formatting.ipynb                sympy_quantum_computing.ipynb
+Script Magics.ipynb             octavemagic_extension.ipynb     trapezoid_rule.ipynb
+animation.m4v                   progbar.ipynb
+
+
+
+
+
+
+
+
+
In [3]:
+
+
message = 'The IPython notebook is great!'
+# note: the echo command does not run on Windows, it's a unix command.
+!echo $message
+
+ +
+
+
+
+
+
+
+
+
+
+
The IPython notebook is great!
+
+
+
+
+
+
+
+
+
+

+ Plots with matplotlib +

+
+ +
+

IPython adds an 'inline' matplotlib backend, +which embeds any matplotlib figures into the notebook.

+
+
+
+
In [4]:
+
+
%pylab inline
+
+ +
+
+
+
+
+
+
+
+
+
+
+Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
+For more information, type 'help(pylab)'.
+
+
+
+
+
+
+
+
+
In [5]:
+
+
x = linspace(0, 3*pi, 500)
+plot(x, sin(x**2))
+title('A simple chirp');
+
+ +
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+

You can paste blocks of input with prompt markers, such as those from +the official Python tutorial

+
+
+
+
In [6]:
+
+
>>> the_world_is_flat = 1
+>>> if the_world_is_flat:
+...     print "Be careful not to fall off!"
+
+ +
+
+
+
+
+
+
+
+
+
+
Be careful not to fall off!
+
+
+
+
+
+
+
+

Errors are shown in informative ways:

+
+
+
+
In [7]:
+
+
%run non_existent_file
+
+ +
+
+
+
+
+
+
+
+
+
+
ERROR: File `u'non_existent_file.py'` not found.
+
+
+
+
+
+
+
+
In [8]:
+
+
x = 1
+y = 4
+z = y/(1-x)
+
+ +
+
+
+
+
+
+
+
+
+
+
+---------------------------------------------------------------------------
+ZeroDivisionError                         Traceback (most recent call last)
+<ipython-input-8-dc39888fd1d2> in <module>()
+      1 x = 1
+      2 y = 4
+----> 3 z = y/(1-x)
+
+ZeroDivisionError: integer division or modulo by zero
+
+
+
+
+
+
+

When IPython needs to display additional information (such as providing details on an object via x? +it will automatically invoke a pager at the bottom of the screen:

+
+ +
+
+
In [18]:
+
+
magic
+
+ +
+
+
+
+
+
+
+

Non-blocking output of kernel

+

If you execute the next cell, you will see the output arriving as it is generated, not all at the end.

+
+
+
+
In [19]:
+
+
import time, sys
+for i in range(8):
+    print i,
+    time.sleep(0.5)
+
+ +
+
+
+
+
+
+
+
+
+
+
0 1 2 3 4 5 6 7
+
+
+
+
+
+
+
+
+
+

Clean crash and restart

+

We call the low-level system libc.time routine with the wrong argument via +ctypes to segfault the Python interpreter:

+
+
+
+
In [*]:
+
+
import sys
+from ctypes import CDLL
+# This will crash a Linux or Mac system; equivalent calls can be made on Windows
+dll = 'dylib' if sys.platform == 'darwin' else '.so.6'
+libc = CDLL("libc.%s" % dll) 
+libc.time(-1)  # BOOM!!
+
+ +
+
+
+
+
+
+

Markdown cells can contain formatted text and code

+

You can italicize, boldface

+
    +
  • build
  • +
  • lists
  • +
+

and embed code meant for illustration instead of execution in Python:

+
def f(x):
+    """a docstring"""
+    return x**2
+
+

or other languages:

+
if (i=0; i<n; i++) {
+  printf("hello %d\n", i);
+  x += 4;
+}
+
+
+
+

Courtesy of MathJax, you can include mathematical expressions both inline: +$e^{i\pi} + 1 = 0$ and displayed:

+

$$e^x=\sum_{i=0}^\infty \frac{1}{i!}x^i$$

+
+
+
+
+

Rich displays: include anyting a browser can show

+

Note that we have an actual protocol for this, see the display_protocol notebook for further details.

+

Images

+
+
+
+
In [1]:
+
+
from IPython.display import Image
+Image(filename='../../source/_static/logo.png')
+
+ +
+
+
+
+
+
Out[1]:
+
+
+
+
+ + +
+
+
+
+
+
+

An image can also be displayed from raw data or a url

+
+
+
+
In [2]:
+
+
Image(url='http://python.org/images/python-logo.gif')
+
+ +
+
+
+
+
+
Out[2]:
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+

SVG images are also supported out of the box (since modern browsers do a good job of rendering them):

+
+
+ +
+
+
In [3]:
+
+
from IPython.display import SVG
+SVG(filename='python-logo.svg')
+
+ +
+
+
+
+
+
Out[3]:
+
+
+
+
+ + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+

Embedded vs Non-embedded Images

+
+
+

As of IPython 0.13, images are embedded by default for compatibility with QtConsole, and the ability to still be displayed offline.

+

Let's look at the differences:

+
+
+
+
In [4]:
+
+
# by default Image data are embedded
+Embed      = Image(    'http://scienceview.berkeley.edu/view/images/newview.jpg')
+
+# if kwarg `url` is given, the embedding is assumed to be false
+SoftLinked = Image(url='http://scienceview.berkeley.edu/view/images/newview.jpg')
+
+# In each case, embed can be specified explicitly with the `embed` kwarg
+# ForceEmbed = Image(url='http://scienceview.berkeley.edu/view/images/newview.jpg', embed=True)
+
+ +
+
+
+
+

Today's image from a webcam at Berkeley, (at the time I created this notebook). This should also work in the Qtconsole. +Drawback is that the saved notebook will be larger, but the image will still be present offline.

+
+
+
+
In [5]:
+
+
Embed
+
+ +
+
+
+
+
+
Out[5]:
+
+
+
+
+ + +
+
+
+
+
+
+

Today's image from same webcam at Berkeley, (refreshed every minutes, if you reload the notebook), visible only with an active internet connexion, that should be different from the previous one. This will not work on Qtconsole. +Notebook saved with this kind of image will be lighter and always reflect the current version of the source, but the image won't display offline.

+
+
+
+
In [6]:
+
+
SoftLinked
+
+ +
+
+
+
+
+
Out[6]:
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+

Of course, if you re-run the all notebook, the two images will be the same again.

+
+
+
+
+
+

Video

+
+
+

And more exotic objects can also be displayed, as long as their representation supports +the IPython display protocol.

+

For example, videos hosted externally on YouTube are easy to load (and writing a similar wrapper for other +hosted content is trivial):

+
+
+
+
In [7]:
+
+
from IPython.display import YouTubeVideo
+# a talk about IPython at Sage Days at U. Washington, Seattle.
+# Video credit: William Stein.
+YouTubeVideo('1j_HxD4iLn8')
+
+ +
+
+
+
+
+
Out[7]:
+
+
+
+
+
+ + + +
+
+
+
+
+
+ +
+

Using the nascent video capabilities of modern browsers, you may also be able to display local +videos. At the moment this doesn't work very well in all browsers, so it may or may not work for you; +we will continue testing this and looking for ways to make it more robust.
+

+

The following cell loads a local file called animation.m4v, encodes the raw video as base64 for http +transport, and uses the HTML5 video tag to load it. On Chrome 15 it works correctly, displaying a control +bar at the bottom with a play/pause button and a location slider.

+
+
+ +
+
+
In [8]:
+
+
from IPython.display import HTML
+video = open("animation.m4v", "rb").read()
+video_encoded = video.encode("base64")
+video_tag = '<video controls alt="test" src="data:video/x-m4v;base64,{0}">'.format(video_encoded)
+HTML(data=video_tag)
+
+ +
+
+
+
+
+
Out[8]:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Local Files

+

The above examples embed images and video from the notebook filesystem in the output +areas of code cells. It is also possible to request these files directly in markdown cells +if they reside in the notebook directory via relative urls prefixed with files/:

+
files/[subdirectory/]<filename>
+
+
+ +
+

For example, in the example notebook folder, we have the Python logo, addressed as:

+
<img src="files/python-logo.svg" />
+
+

+

and a video with the HTML5 video tag:

+
<video controls src="files/animation.m4v" />
+
+
+
+
+
+
+

Linking to files and directories for viewing in the browser

+

It is also possible to link directly to files or directories so they can be opened in the browser. This is especially convenient if you're interacting with a tool within IPython that generates HTML pages, and you'd like to easily be able to open those in a new browser window. Alternatively, if your IPython notebook server is on a remote system, creating links provides an easy way to download any files that get generated.

+

As we saw above, there are a bunch of .ipynb files in our current directory.

+
+
+
+
In [1]:
+
+
ls
+
+ +
+
+
+
+
+
+
+
+
+
+
00_notebook_tour.ipynb          formatting.ipynb
+01_notebook_introduction.ipynb  octavemagic_extension.ipynb
+Animations_and_Progress.ipynb   publish_data.ipynb
+Capturing Output.ipynb          python-logo.svg
+Script Magics.ipynb             rmagic_extension.ipynb
+animation.m4v                   sympy.ipynb
+cython_extension.ipynb          sympy_quantum_computing.ipynb
+display_protocol.ipynb          trapezoid_rule.ipynb
+
+
+
+
+
+
+
+

If we want to create a link to one of them, we can call use the FileLink object.

+
+
+
+
In [2]:
+
+
from IPython.display import FileLink
+FileLink('00_notebook_tour.ipynb')
+
+ +
+
+
+
+
+
Out[2]:
+
+ +
+
+
+
+

Alternatively, if we want to link to all of them, we can use the FileLinks object, passing '.' to indicate that we want links generated for the current working directory. Note that if there were other directories under the current directory, FileLinks would work in a recursive manner creating links to files in all sub-directories as well.

+
+
+
+
+
+

External sites

+

You can even embed an entire page from another site in an iframe; for example this is today's Wikipedia +page for mobile users:

+
+
+
+
In [9]:
+
+
HTML('<iframe src=http://en.mobile.wikipedia.org/?useformat=mobile width=700 height=350></iframe>')
+
+ +
+
+
+
+
+
Out[9]:
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+

Mathematics

+

And we also support the display of mathematical expressions typeset in LaTeX, which is rendered +in the browser thanks to the MathJax library.
+

+

Note that this is different from the above examples. Above we were typing mathematical expressions +in Markdown cells (along with normal text) and letting the browser render them; now we are displaying +the output of a Python computation as a LaTeX expression wrapped by the Math() object so the browser +renders it. The Math object will add the needed LaTeX delimiters ($$) if they are not provided:

+
+
+
+
In [10]:
+
+
from IPython.display import Math
+Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')
+
+ +
+
+
+
+
+
Out[10]:
+
+
+
+
+ +$$F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx$$ +
+
+
+
+
+
+

With the Latex class, you have to include the delimiters yourself. This allows you to use other LaTeX modes such as eqnarray:

+
+
+
+
In [11]:
+
+
from IPython.display import Latex
+Latex(r"""\begin{eqnarray}
+\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
+\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
+\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
+\nabla \cdot \vec{\mathbf{B}} & = 0 
+\end{eqnarray}""")
+
+ +
+
+
+
+
+
Out[11]:
+
+
+
+
+ +\begin{eqnarray} +\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ +\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ +\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ +\nabla \cdot \vec{\mathbf{B}} & = 0 +\end{eqnarray} +
+
+
+
+
+
+

Or you can enter latex directly with the %%latex cell magic:

+
+
+
+
In [12]:
+
+
%%latex
+\begin{aligned}
+\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
+\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
+\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
+\nabla \cdot \vec{\mathbf{B}} & = 0
+\end{aligned}
+
+ +
+
+
+
+
+
+
+
+
+
+ +\begin{aligned} +\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ +\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ +\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ +\nabla \cdot \vec{\mathbf{B}} & = 0 +\end{aligned} +
+
+
+
+
+ +
+

There is also a %%javascript cell magic for running javascript directly, +and %%svg for manually entering SVG content.

+
+
+
+
+
+

Loading external codes

+ +

In this notebook we've kept the output saved so you can see the result, but you should run the next +cell yourself (with an active internet connection).

+
+
+

Let's make sure we have pylab again, in case we have restarted the kernel due to the crash demo above

+
+ +
+
+
In [12]:
+
+
%pylab inline
+
+ +
+
+
+
+
+
+
+
+
+
+
+Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
+For more information, type 'help(pylab)'.
+
+
+
+
+
+
+
+ +
+
+
In [15]:
+
+
%load http://matplotlib.sourceforge.net/mpl_examples/pylab_examples/integral_demo.py
+
+ +
+
+
+
+ +
+
+
In [16]:
+
+
#!/usr/bin/env python
+
+# implement the example graphs/integral from pyx
+from pylab import *
+from matplotlib.patches import Polygon
+
+def func(x):
+    return (x-3)*(x-5)*(x-7)+85
+
+ax = subplot(111)
+
+a, b = 2, 9 # integral area
+x = arange(0, 10, 0.01)
+y = func(x)
+plot(x, y, linewidth=1)
+
+# make the shaded region
+ix = arange(a, b, 0.01)
+iy = func(ix)
+verts = [(a,0)] + zip(ix,iy) + [(b,0)]
+poly = Polygon(verts, facecolor='0.8', edgecolor='k')
+ax.add_patch(poly)
+
+text(0.5 * (a + b), 30,
+     r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center',
+     fontsize=20)
+
+axis([0,10, 0, 180])
+figtext(0.9, 0.05, 'x')
+figtext(0.1, 0.9, 'y')
+ax.set_xticks((a,b))
+ax.set_xticklabels(('a','b'))
+ax.set_yticks([])
+show()
+
+ +
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+ +
+ + +
+ + + + + +
+ + + + + + + + + + + + +