Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MEP 12: Gallery cleanup and reorganization #1623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
31c4b57
STY: Refactor string formatting/templating
tonysyu Dec 18, 2012
a16e793
Clean-up and move scatter_demo
tonysyu Dec 18, 2012
a22ed53
Cleanup and move fill_demo
tonysyu Dec 18, 2012
48caac8
Cleanup and move pie_demo
tonysyu Dec 18, 2012
7f1887b
Cleanup and move errorbar_demo.
tonysyu Dec 18, 2012
b10a877
Cleanup and move fill_demo2
tonysyu Dec 18, 2012
6995e54
Cleanup and move histogram_demo
tonysyu Dec 18, 2012
48fab58
Cleanup and move hinton_demo
tonysyu Dec 18, 2012
e9bfbb9
Cleanup and move image_demo3.py
tonysyu Dec 18, 2012
87aba29
DOC: Minor rewording
tonysyu Dec 21, 2012
c0f42d7
Fix doc build to search in new example sections.
tonysyu Dec 21, 2012
e244d9b
Cleanup and move subplot_demo
tonysyu Dec 21, 2012
002ca7a
Update example section titles
tonysyu Dec 21, 2012
402b301
Cleanup and move unicode_demo
tonysyu Dec 21, 2012
529d9f7
Consolidate histogram examples
tonysyu Dec 22, 2012
6acc43a
Cleanup and move vertical_ticklabels demo
tonysyu Dec 22, 2012
7f7c013
Cleanup and move clippath_demo
tonysyu Dec 23, 2012
ab417eb
Rename imshow_demo to image_demo
tonysyu Dec 23, 2012
5a77ad8
Cleanup and move polar_bar demo
tonysyu Dec 23, 2012
e4dce4e
Cleanup and move polar scatter demo
tonysyu Dec 23, 2012
cc18501
Cleanup and move text themes demo
tonysyu Dec 23, 2012
d02d560
Cleanup and move path_patch demo
tonysyu Dec 23, 2012
ec8a487
Clean up and move integral demo
tonysyu Dec 23, 2012
acc69cc
Extract spines_demo_bounds from spine_placement_demo
tonysyu Dec 23, 2012
800deb4
Extract spines_demo from spine_placement_demo
tonysyu Dec 23, 2012
edce62b
Cleanup integral_demo
tonysyu Dec 23, 2012
405cbc5
Cleanup and move dash_control demo
tonysyu Dec 23, 2012
30a85ba
Clean up and move color_cycle demo
tonysyu Dec 24, 2012
7175e06
Tweak subplot layout to prevent label clipping
tonysyu Dec 24, 2012
5020952
Add colormap references based on show_colormaps
tonysyu Dec 24, 2012
fae23d6
Clean up and move artist demo
tonysyu Dec 24, 2012
abfdea4
Clean up and move streamplot demos
tonysyu Dec 24, 2012
8f4be5b
Combine colormap reference examples
tonysyu Dec 24, 2012
917c329
Clean up and move barh_demo
tonysyu Dec 24, 2012
1e579d8
STY: Combine declarations of example directories
tonysyu Dec 30, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@

plot_formats = [('png', 80), ('hires.png', 200), ('pdf', 50)]

# Subdirectories in 'examples/' directory of package and titles for gallery
# TODO: Change to OrderedDict when Matplotlib drops support for Python < 2.7
mpl_example_sections = (
('lines_bars_and_markers', 'Lines, bars, and markers'),
('shapes_and_collections', 'Shapes and collections'),
('statistics', 'Statistical plots'),
('images_contours_and_fields', 'Images, contours, and fields'),
('pie_and_polar_charts', 'Pie and polar charts'),
('color', 'Color'),
('text_labels_and_annotations', 'Text, labels, and annotations'),
('ticks_and_spines', 'Ticks and spines'),
('subplots_axes_and_figures', 'Subplots, axes, and figures'),
('specialty_plots', 'Specialty plots'),
('showcase', 'Showcase'),
('api', 'API'),
('pylab_examples', 'pylab examples'),
('mplot3d', 'mplot3d toolkit'),
('axes_grid', 'axes_grid toolkit'),
('units', 'units'),
('widgets', 'widgets'),
)


# Github extension

github_project_url = "http://github.com/matplotlib/matplotlib/"
Expand Down
93 changes: 59 additions & 34 deletions doc/sphinxext/gen_gallery.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,74 @@
# -*- coding: UTF-8 -*-
import os
import re
import glob
import warnings

import sphinx.errors

import matplotlib.image as image


exclude_example_sections = ['units']
multiimage = re.compile('(.*?)(_\d\d){1,2}')

# generate a thumbnail gallery of examples
template = """\
{%% extends "layout.html" %%}
{%% set title = "Thumbnail gallery" %%}
gallery_template = """\
{{% extends "layout.html" %}}
{{% set title = "Thumbnail gallery" %}}


{%% block body %%}
{{% block body %}}

<h3>Click on any image to see full size image and source code</h3>
<br/>

<li><a class="reference internal" href="#">Gallery</a><ul>
%s
</ul>
<li><a class="reference internal" href="#">Gallery</a>
<ul>
{toc}
</ul>
</li>

%s
{%% endblock %%}
{gallery}

{{% endblock %}}
"""

import os, glob, re, sys, warnings
import matplotlib.image as image
header_template = """\
<div class="section" id="{section}">
<h4>
{title}<a class="headerlink" href="#{section}" title="Permalink to this headline">¶</a>
</h4>"""

link_template = """\
<a href="{link}"><img src="{thumb}" border="0" alt="{basename}"/></a>
"""

toc_template = """\
<li><a class="reference internal" href="#{section}">{title}</a></li>"""

multiimage = re.compile('(.*?)(_\d\d){1,2}')

def make_thumbnail(args):
image.thumbnail(args[0], args[1], 0.3)


def out_of_date(original, derived):
return (not os.path.exists(derived) or
os.stat(derived).st_mtime < os.stat(original).st_mtime)


def gen_gallery(app, doctree):
if app.builder.name != 'html':
return

outdir = app.builder.outdir
rootdir = 'plot_directive/mpl_examples'

example_sections = list(app.builder.config.mpl_example_sections)
for i, (subdir, title) in enumerate(example_sections):
if subdir in exclude_example_sections:
example_sections.pop(i)

# images we want to skip for the gallery because they are an unusual
# size that doesn't layout well in a table, or because they may be
# redundant with other images or uninteresting
Expand All @@ -53,21 +83,9 @@ def gen_gallery(app, doctree):
rows = []
toc_rows = []

link_template = """\
<a href="%s"><img src="%s" border="0" alt="%s"/></a>
"""

header_template = """<div class="section" id="%s">\
<h4>%s<a class="headerlink" href="#%s" title="Permalink to this headline">¶</a></h4>"""

toc_template = """\
<li><a class="reference internal" href="#%s">%s</a></li>"""

dirs = ('api', 'pylab_examples', 'mplot3d', 'widgets', 'axes_grid' )

for subdir in dirs :
rows.append(header_template % (subdir, subdir, subdir))
toc_rows.append(toc_template % (subdir, subdir))
for subdir, title in example_sections:
rows.append(header_template.format(title=title, section=subdir))
toc_rows.append(toc_template.format(title=title, section=subdir))

origdir = os.path.join('build', rootdir, subdir)
thumbdir = os.path.join(outdir, rootdir, subdir, 'thumbnails')
Expand Down Expand Up @@ -99,33 +117,34 @@ def gen_gallery(app, doctree):
data.append((subdir, basename,
os.path.join(rootdir, subdir, 'thumbnails', filename)))




for (subdir, basename, thumbfile) in data:
if thumbfile is not None:
link = 'examples/%s/%s.html'%(subdir, basename)
rows.append(link_template%(link, thumbfile, basename))
rows.append(link_template.format(link=link,
thumb=thumbfile,
basename=basename))

if len(data) == 0:
warnings.warn("No thumbnails were found in %s" % subdir)

# Close out the <div> opened up at the top of this loop
rows.append("</div>")

content = template % ('\n'.join(toc_rows),
'\n'.join(rows))
content = gallery_template.format(toc='\n'.join(toc_rows),
gallery='\n'.join(rows))

# Only write out the file if the contents have actually changed.
# Otherwise, this triggers a full rebuild of the docs

gallery_path = os.path.join(app.builder.srcdir, '_templates', 'gallery.html')
gallery_path = os.path.join(app.builder.srcdir,
'_templates', 'gallery.html')
if os.path.exists(gallery_path):
fh = file(gallery_path, 'r')
regenerate = fh.read() != content
fh.close()
else:
regenerate = True

if regenerate:
fh = file(gallery_path, 'w')
fh.write(content)
Expand All @@ -136,5 +155,11 @@ def gen_gallery(app, doctree):
length=len(thumbnails)):
image.thumbnail(key, thumbnails[key], 0.3)


def setup(app):
app.connect('env-updated', gen_gallery)

try: # multiple plugins may use mpl_example_sections
app.add_config_value('mpl_example_sections', [], True)
except sphinx.errors.ExtensionError:
pass # mpl_example_sections already defined
31 changes: 20 additions & 11 deletions doc/sphinxext/gen_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
generate the rst files for the examples by iterating over the pylab examples
"""
from __future__ import print_function
import os, glob

import os
import re
import sys
fileList = []

import sphinx.errors


exclude_example_sections = ['widgets']
noplot_regex = re.compile(r"#\s*-\*-\s*noplot\s*-\*-")


def out_of_date(original, derived):
"""
Expand All @@ -21,14 +26,18 @@ def out_of_date(original, derived):
return (not os.path.exists(derived) or
os.stat(derived).st_mtime < os.stat(original).st_mtime)

noplot_regex = re.compile(r"#\s*-\*-\s*noplot\s*-\*-")

def generate_example_rst(app):
rootdir = os.path.join(app.builder.srcdir, 'mpl_examples')
exampledir = os.path.join(app.builder.srcdir, 'examples')
if not os.path.exists(exampledir):
os.makedirs(exampledir)

example_sections = list(app.builder.config.mpl_example_sections)
for i, (subdir, title) in enumerate(example_sections):
if subdir in exclude_example_sections:
example_sections.pop(i)
example_subdirs, titles = zip(*example_sections)

datad = {}
for root, subFolders, files in os.walk(rootdir):
for fname in files:
Expand Down Expand Up @@ -114,13 +123,8 @@ def generate_example_rst(app):

fhsubdirIndex.write(' %s <%s>\n'%(os.path.basename(basename),rstfile))

do_plot = (subdir in ('api',
'pylab_examples',
'units',
'mplot3d',
'axes_grid',
) and
not noplot_regex.search(contents))
do_plot = (subdir in example_subdirs
and not noplot_regex.search(contents))
if not do_plot:
fhstatic = file(outputfile, 'w')
fhstatic.write(contents)
Expand Down Expand Up @@ -157,3 +161,8 @@ def generate_example_rst(app):

def setup(app):
app.connect('builder-inited', generate_example_rst)

try: # multiple plugins may use mpl_example_sections
app.add_config_value('mpl_example_sections', [], True)
except sphinx.errors.ExtensionError:
pass # mpl_example_sections already defined
2 changes: 1 addition & 1 deletion doc/users/image_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ object:

There are many other colormap schemes available. See the `list and
images of the colormaps
<http://matplotlib.org/examples/pylab_examples/show_colormaps.html>`_.
<http://matplotlib.org/examples/color/colormaps_reference.html>`_.

.. _`Color Bars`:

Expand Down
10 changes: 5 additions & 5 deletions doc/users/screenshots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Subplot demo
Multiple regular axes (numrows by numcolumns) are created with the
:func:`~matplotlib.pyplot.subplot` command.

.. plot:: mpl_examples/pylab_examples/subplot_demo.py
.. plot:: mpl_examples/subplots_axes_and_figures/subplot_demo.py

.. _screenshots_histogram_demo:

Expand All @@ -32,7 +32,7 @@ Histograms
The :func:`~matplotlib.pyplot.hist` command automatically generates
histograms and will return the bin counts or probabilities

.. plot:: mpl_examples/pylab_examples/histogram_demo.py
.. plot:: mpl_examples/statistics/histogram_demo_features.py


.. _screenshots_path_demo:
Expand All @@ -43,7 +43,7 @@ Path demo
You can add arbitrary paths in matplotlib as of release 0.98. See
the :mod:`matplotlib.path`.

.. plot:: mpl_examples/api/path_patch_demo.py
.. plot:: mpl_examples/shapes_and_collections/path_patch_demo.py

.. _screenshots_mplot3d_surface:

Expand Down Expand Up @@ -103,7 +103,7 @@ or more wedges out from the center of the pie, and a shadow effect.
Take a close look at the attached code that produced this figure; nine
lines of code.

.. plot:: mpl_examples/pylab_examples/pie_demo.py
.. plot:: mpl_examples/pie_and_polar_charts/pie_demo_features.py

.. _screenshots_table_demo:

Expand Down Expand Up @@ -153,7 +153,7 @@ The :func:`~matplotlib.pyplot.fill` command lets you
plot filled polygons. Thanks to Andrew Straw for providing this
function

.. plot:: mpl_examples/pylab_examples/fill_demo.py
.. plot:: mpl_examples/lines_bars_and_markers/fill_demo.py


.. _screenshots_date_demo:
Expand Down
4 changes: 2 additions & 2 deletions doc/users/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ In addition to simply plotting the streamlines of the vector field,
line widths of the streamlines to a separate parameter, such as the speed or
local intensity of the vector field.

.. plot:: mpl_examples/pylab_examples/streamplot_demo.py
.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo_features.py


New hist functionality
Expand Down Expand Up @@ -442,7 +442,7 @@ Other improvements

* Pim Schellart added a new colormap called "cubehelix".
Sameer Grover also added a colormap called "coolwarm". See it and all
other colormaps :ref:`here <pylab_examples-show_colormaps>`.
other colormaps :ref:`here <color-colormaps_reference>`.

* Many bug fixes and documentation improvements.

Expand Down
Loading