It's an extension that builds an HTML version of any python script and puts it into an examples gallery.
awesome_python_project
├── doc
│ ├── conf.py
│ ├── index.rst
│ └── Makefile
├── examples
│ ├── README.txt
│ └── plot_colors.py
...
Introduce your Gallery in examples/README.txt
.. _My_Gallery:
My Gallery
==========
Colormaps Examples
------------------
Colormap examples using Sphinx-Gallery
With the plot_ prefix Sphinx-Gallery executes the script
# -*- coding: utf-8 -*-
r"""
===============================
Colormaps alter your perception
===============================
Here I plot the function
.. math:: f(x, y) = \sin(x) + \cos(y)
with different colormaps.
"""
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-np.pi, np.pi, 300)
xx, yy = np.meshgrid(x, x)
z = np.cos(xx) + np.cos(yy)
plt.figure()
plt.imshow(z)
plt.figure()
plt.imshow(z, cmap=plt.cm.get_cmap('hot'))
plt.figure()
plt.imshow(z, cmap=plt.cm.get_cmap('Spectral'),
interpolation='none')
# Not needed for the Gallery.
# Only for direct execution
plt.show()
################################################
# You can define blocks in your source code
# with interleaving prose.
#
print("This writes to stdout and will be",
" displayed in the HTML file")
Install it with:
$ pip install sphinx-gallery
Edit the doc/conf.py file with
import sphinx_gallery
extensions = [
...
'sphinx_gallery.gen_gallery',
]
sphinx_gallery_conf = {
# path to your examples scripts
'examples_dirs' : '../examples',
# path where to save gallery generated examples
'gallery_dirs' : 'auto_examples'}
Build the Documentation
$ make html
Start using and contributing to Sphinx-Gallery