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

Skip to content

Commit 529c88e

Browse files
committed
cleaned up output of mathmpl and plot directive; added thumbnail gallery
svn path=/trunk/matplotlib/; revision=6287
1 parent 9f0a285 commit 529c88e

17 files changed

Lines changed: 769 additions & 79 deletions

File tree

doc/_templates/gallery.html

Lines changed: 498 additions & 0 deletions
Large diffs are not rendered by default.

doc/_templates/gen_gallery.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# generate a thumbnail gallery of examples
2+
template = """\
3+
{%% extends "layout.html" %%}
4+
{%% set title = "Thumbnail gallery" %%}
5+
6+
7+
{%% block body %%}
8+
9+
<h3>Click on any image to see full size image and source code</h3>
10+
<br>
11+
12+
%s
13+
{%% endblock %%}
14+
"""
15+
16+
import os, glob, re
17+
18+
multiimage = re.compile('(.*)_\d\d')
19+
20+
pwd = os.getcwd()
21+
os.chdir('..')
22+
23+
rootdir = '_static/plot_directive/mpl_examples'
24+
25+
# images we want to skip for the gallery because they are an unusual
26+
# size that doesn't layout well in a table, or because they may be
27+
# redundant with other images or uninteresting
28+
skips = set([
29+
'mathtext_examples',
30+
'matshow_02',
31+
'matshow_03',
32+
'matplotlib_icon',
33+
])
34+
data = []
35+
for subdir in ('api', 'pylab_examples', 'widgets'):
36+
thisdir = os.path.join(rootdir,subdir)
37+
if not os.path.exists(thisdir):
38+
raise RuntimeError('Cannot find %s'%thisdir)
39+
thumbdir = os.path.join(thisdir, 'thumbnails')
40+
if not os.path.exists(thumbdir):
41+
raise RuntimeError('Cannot find thumbnail dir %s'%thumbdir)
42+
#print thumbdir
43+
44+
# we search for pdfs here because there is one pdf for each
45+
# successful image build (2 pngs since one is high res) and the
46+
# mapping between py files and images is 1->many
47+
for pdffile in sorted(glob.glob(os.path.join(thisdir, '*.pdf'))):
48+
basepath, filename = os.path.split(pdffile)
49+
basename, ext = os.path.splitext(filename)
50+
print 'generating', subdir, basename
51+
52+
if basename in skips:
53+
print ' skipping', basename
54+
continue
55+
pngfile = os.path.join(thisdir, '%s.png'%basename)
56+
thumbfile = os.path.join(thumbdir, '%s.png'%basename)
57+
if not os.path.exists(pngfile):
58+
pngfile = None
59+
if not os.path.exists(thumbfile):
60+
thumbfile = None
61+
62+
m = multiimage.match(basename)
63+
if m is None:
64+
pyfile = '%s.py'%basename
65+
else:
66+
basename = m.group(1)
67+
pyfile = '%s.py'%basename
68+
69+
print ' ', pyfile, filename, basename, ext
70+
71+
print ' ', pyfile, pngfile, thumbfile
72+
data.append((subdir, thisdir, pyfile, basename, pngfile, thumbfile))
73+
74+
link_template = """\
75+
<a href="%s"><img src="%s" border="0" alt="%s"/></a>
76+
"""
77+
78+
79+
rows = []
80+
for (subdir, thisdir, pyfile, basename, pngfile, thumbfile) in data:
81+
if thumbfile is not None:
82+
link = 'examples/%s/%s.html'%(subdir, basename)
83+
rows.append(link_template%(link, thumbfile, basename))
84+
85+
86+
87+
os.chdir(pwd)
88+
fh = file('gallery.html', 'w')
89+
fh.write(template%'\n'.join(rows))
90+
fh.close()
91+

doc/_templates/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ <h1>Welcome</h1>
1515

1616
<p>matplotlib tries to make easy things easy and hard things possible.
1717
You can generate plots, histograms, power spectra, bar charts,
18-
errorcharts, scatterplots, etc, with just a few lines of code.
19-
For a sampling, see the <a href="{{ pathto('users/screenshots') }}">screenshots</a> and
20-
<a href="examples/index.html">examples</a></p>
18+
errorcharts, scatterplots, etc, with just a few lines of code.
19+
For a sampling, see the <a href="{{ pathto('users/screenshots') }}">screenshots</a>, <a href="{{ pathto('gallery') }}">thumbnail gallery</a>, and
20+
<a href="examples/index.html">examples</a> directory</p>
2121

2222
<p align="center"><a href="{{ pathto('users/screenshots') }}"><img align="middle"
2323
src="{{ pathto('_static/logo_sidebar_horiz.png', 1) }}" border="0"
@@ -35,7 +35,7 @@ <h1>Welcome</h1>
3535

3636
<p>For the power user, you have full control of line styles, font
3737
properties, axes properties, etc, via an object oriented interface
38-
or via a handle graphics interface familiar to Matlab&reg; users.
38+
or via a handle graphics interface familiar to Matlab&reg; users.
3939
The plotting functions in the <a href="api/pyplot_api.html">pyplot</a>
4040
interface have a high degree of Matlab&reg; compatibility.</p>
4141

doc/_templates/layout.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{% block rootrellink %}
44
<li><a href="{{ pathto('index') }}">matplotlib&nbsp;home</a>|&nbsp;</li>
55
<li><a href="{{ pathto('search') }}">search</a>|&nbsp;</li>
6+
<li><a href="{{ pathto('gallery') }}">gallery</a>|&nbsp;</li>
67
<li><a href="{{ pathto('contents') }}">documentation </a> &raquo;</li>
78
{% endblock %}
89

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123

124124
# Additional templates that should be rendered to pages, maps page names to
125125
# template names.
126-
html_additional_pages = {'index': 'index.html'}
126+
html_additional_pages = {'index': 'index.html', 'gallery':'gallery.html'}
127127

128128
# If false, no module index is generated.
129129
#html_use_modindex = True

doc/devel/coding_guide.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,34 @@ There are some some manual hacks in this case, violating the
352352
"single entry point" requirement above -- see the
353353
``artist.kwdocd['Patch']`` setting in :mod:`matplotlib.patches`.
354354

355+
.. _custom_backend:
356+
357+
Developing a new backend
358+
========================
359+
360+
If you are working on a custom backend, the *backend* setting in
361+
:file:`matplotlibrc` (:ref:`customizing-matplotlib`) supports an
362+
external backend via the ``module`` directive. if
363+
:file:`my_backend.py` is a matplotlib backend in your
364+
:envvar:`PYTHONPATH`, you can set use it on one of several ways
365+
366+
* in matplotlibrc::
367+
368+
backend : module://my_backend
369+
370+
* with the use directive is your script::
371+
372+
import matplotlib
373+
matplotlib.use('module://my_backend')
374+
375+
* from the command shell with the -d flag::
376+
377+
> python simple_plot.py -d module://my_backend
378+
379+
380+
381+
382+
355383

356384
.. _license-discussion:
357385

doc/examples/gen_rst.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"""
44
import os, glob
55

6-
import matplotlib.cbook as cbook
7-
86
import os
97
import re
108
import sys
@@ -75,8 +73,10 @@ def out_of_date(original, derived):
7573

7674
subdirIndexFile = os.path.join(subdir, 'index.rst')
7775
fhsubdirIndex = file(subdirIndexFile, 'w')
78-
fhindex.write(' %s\n'%subdirIndexFile)
79-
76+
fhindex.write(' %s\n\n'%subdirIndexFile)
77+
#thumbdir = '../_static/plot_directive/mpl_examples/%s/thumbnails/'%subdir
78+
#for thumbname in glob.glob(os.path.join(thumbdir,'*.png')):
79+
# fhindex.write(' %s\n'%thumbname)
8080

8181
fhsubdirIndex.write("""\
8282
.. _%s-examples-index:
@@ -101,15 +101,23 @@ def out_of_date(original, derived):
101101

102102
data = datad[subdir]
103103
data.sort()
104-
for fullname, fname, contents in data:
105-
static_file = os.path.join(static_dir, fname)
104+
105+
#parts = os.path.split(static_dir)
106+
#thumb_dir = ('../'*(len(parts)-1)) + os.path.join(static_dir, 'thumbnails')
107+
108+
for fullpath, fname, contents in data:
106109
basename, ext = os.path.splitext(fname)
110+
static_file = os.path.join(static_dir, fname)
111+
#thumbfile = os.path.join(thumb_dir, '%s.png'%basename)
112+
#print ' static_dir=%s, basename=%s, fullpath=%s, fname=%s, thumb_dir=%s, thumbfile=%s'%(static_dir, basename, fullpath, fname, thumb_dir, thumbfile)
113+
107114
rstfile = '%s.rst'%basename
108115
outfile = os.path.join(subdir, rstfile)
116+
109117
fhsubdirIndex.write(' %s\n'%rstfile)
110118

111-
if (not out_of_date(fullname, static_file) and
112-
not out_of_date(fullname, outfile)):
119+
if (not out_of_date(fullpath, static_file) and
120+
not out_of_date(fullpath, outfile)):
113121
continue
114122

115123
print ' %s'%fname
@@ -121,6 +129,8 @@ def out_of_date(original, derived):
121129
fh = file(outfile, 'w')
122130
fh.write('.. _%s-%s:\n\n'%(subdir, basename))
123131
title = '%s example code: %s'%(subdir, fname)
132+
#title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)
133+
124134

125135
fh.write(title + '\n')
126136
fh.write('='*len(title) + '\n\n')
@@ -131,7 +141,7 @@ def out_of_date(original, derived):
131141
not noplot_regex.search(contents))
132142

133143
if do_plot:
134-
fh.write("\n\n.. plot:: %s\n\n::\n\n" % fullname[3:])
144+
fh.write("\n\n.. plot:: %s\n\n::\n\n" % fullpath[3:])
135145
else:
136146
linkname = os.path.join('..', '..', '_static', 'examples', subdir, fname)
137147
fh.write("[`source code <%s>`_]\n\n::\n\n" % linkname)

doc/faq/environment_variables_faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _environment-variables:
1+
.. _environment-variablesg:
22

33
*********************
44
Environment Variables

doc/faq/installing_faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Install from svn
9898

9999
Checking out the main source::
100100

101-
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk matplotlib
101+
svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk/matplotlib matplotlib
102102

103103
and build and install as usual with::
104104

doc/make.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def check_build():
1717
def sf():
1818
'push a copy to the sf site'
1919
os.system('cd build/html; rsync -avz . jdh2358,[email protected]:/home/groups/m/ma/matplotlib/htdocs/ -essh --cvs-exclude')
20-
# we are now doing this in the doc/examples build
20+
# we are now doing this in the doc/examples build
2121
#os.system('cd ~/mpl/examples; svn-clean; cd ..; rsync -avz examples jdh2358,[email protected]:/home/groups/m/ma/matplotlib/htdocs/ -essh --cvs-exclude --delete')
2222

2323
def sfpdf():
@@ -29,7 +29,14 @@ def figs():
2929

3030
def examples():
3131
'make the rest examples'
32+
3233
os.system('cd examples; svn-clean; python gen_rst.py')
34+
#pass
35+
36+
def gallery():
37+
'make the thumbnail gallery'
38+
os.system('cd _templates; python gen_gallery.py')
39+
3340

3441
def html():
3542
check_build()
@@ -44,6 +51,10 @@ def html():
4451
shutil.rmtree(figures_dest_path)
4552
shutil.copytree('pyplots', figures_dest_path)
4653

54+
# rebuild the gallery
55+
gallery()
56+
print 'Just rebuilt gallery, you may need to make html again'
57+
4758
def latex():
4859
check_build()
4960
#figs()
@@ -77,15 +88,17 @@ def all():
7788
latex()
7889

7990

80-
funcd = {'figs':figs,
81-
'html':html,
82-
'latex':latex,
83-
'clean':clean,
84-
'sf':sf,
85-
'sfpdf':sfpdf,
86-
'examples':examples,
87-
'all':all,
88-
}
91+
funcd = {
92+
'figs' : figs,
93+
'html' : html,
94+
'latex' : latex,
95+
'clean' : clean,
96+
'sf' : sf,
97+
'sfpdf' : sfpdf,
98+
'examples' : examples,
99+
'gallery' : gallery,
100+
'all' : all,
101+
}
89102

90103

91104
if len(sys.argv)>1:

0 commit comments

Comments
 (0)