Revision: 5218
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5218&view=rev
Author: dsdale
Date: 2008-05-22 14:01:40 -0700 (Thu, 22 May 2008)
Log Message:
-----------
minor changes to docstring formatting to support ReST
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/dviread.py
trunk/matplotlib/lib/matplotlib/texmanager.py
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2008-05-22 19:58:22 UTC (rev
5217)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2008-05-22 21:01:40 UTC (rev
5218)
@@ -2722,9 +2722,7 @@
#### Basic plotting
def plot(self, *args, **kwargs):
"""
- PLOT(*args, **kwargs)
-
- Plot lines and/or markers to the Axes. *args is a variable length
+ Plot lines and/or markers to the Axes. ``*args`` is a variable length
argument, allowing for multiple x,y pairs with an optional format
string. For example, each of the following is legal
@@ -2744,32 +2742,32 @@
The following line styles are supported:
- - : solid line
- -- : dashed line
- -. : dash-dot line
- : : dotted line
- . : points
- , : pixels
- o : circle symbols
- ^ : triangle up symbols
- v : triangle down symbols
- < : triangle left symbols
- > : triangle right symbols
- s : square symbols
- + : plus symbols
- x : cross symbols
- D : diamond symbols
- d : thin diamond symbols
- 1 : tripod down symbols
- 2 : tripod up symbols
- 3 : tripod left symbols
- 4 : tripod right symbols
- h : hexagon symbols
- H : rotated hexagon symbols
- p : pentagon symbols
- | : vertical line symbols
- _ : horizontal line symbols
- steps : use gnuplot style 'steps' # kwarg only
+ * - : solid line
+ * -- : dashed line
+ * -. : dash-dot line
+ * : : dotted line
+ * . : points
+ * , : pixels
+ * o : circle symbols
+ * ^ : triangle up symbols
+ * v : triangle down symbols
+ * < : triangle left symbols
+ * > : triangle right symbols
+ * s : square symbols
+ * + : plus symbols
+ * x : cross symbols
+ * D : diamond symbols
+ * d : thin diamond symbols
+ * 1 : tripod down symbols
+ * 2 : tripod up symbols
+ * 3 : tripod left symbols
+ * 4 : tripod right symbols
+ * h : hexagon symbols
+ * H : rotated hexagon symbols
+ * p : pentagon symbols
+ * | : vertical line symbols
+ * _ : horizontal line symbols
+ * steps : use gnuplot style 'steps' # kwarg only
The following color abbreviations are supported
@@ -2792,8 +2790,8 @@
Line styles and colors are combined in a single format string, as in
'bo' for blue circles.
- The **kwargs can be used to set line properties (any property that has
- a set_* method). You can use this to set a line label (for auto
+ The ``**kwargs`` can be used to set line properties (any property that
has
+ a ``set_*`` method). You can use this to set a line label (for auto
legends), linewidth, anitialising, marker face color, etc. Here is an
example:
Modified: trunk/matplotlib/lib/matplotlib/dviread.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/dviread.py 2008-05-22 19:58:22 UTC (rev
5217)
+++ trunk/matplotlib/lib/matplotlib/dviread.py 2008-05-22 21:01:40 UTC (rev
5218)
@@ -3,17 +3,18 @@
limitations make this not (currently) useful as a general-purpose dvi
preprocessor.
-Interface:
+Interface::
- dvi = Dvi(filename, 72)
- for page in dvi: # iterate over pages
- w, h, d = page.width, page.height, page.descent
- for x,y,font,glyph,width in page.text:
- fontname = font.texname
- pointsize = font.size
- ...
- for x,y,height,width in page.boxes:
- ...
+ dvi = Dvi(filename, 72)
+ for page in dvi: # iterate over pages
+ w, h, d = page.width, page.height, page.descent
+ for x,y,font,glyph,width in page.text:
+ fontname = font.texname
+ pointsize = font.size
+ ...
+ for x,y,height,width in page.boxes:
+ ...
+
"""
import matplotlib
@@ -419,12 +420,13 @@
class Vf(Dvi):
"""
- A virtual font (*.vf file) containing subroutines for dvi files.
+ A virtual font (\*.vf file) containing subroutines for dvi files.
- Usage:
- vf = Vf(filename)
- glyph = vf[code]
- glyph.text, glyph.boxes, glyph.width
+ Usage::
+
+ vf = Vf(filename)
+ glyph = vf[code]
+ glyph.text, glyph.boxes, glyph.width
"""
def __init__(self, filename):
@@ -526,12 +528,16 @@
minimum needed by the Dvi class.
Attributes:
+
checksum: for verifying against dvi file
+
design_size: design size of the font (in what units?)
- width[i]: width of character #i, needs to be scaled
+
+ width[i]: width of character \#i, needs to be scaled
by the factor specified in the dvi file
(this is a dict because indexing may not start from 0)
- height[i], depth[i]: height and depth of character #i
+
+ height[i], depth[i]: height and depth of character \#i
"""
__slots__ = ('checksum', 'design_size', 'width', 'height', 'depth')
@@ -665,13 +671,14 @@
class Encoding(object):
"""
- Parses a *.enc file referenced from a psfonts.map style file.
+ Parses a \*.enc file referenced from a psfonts.map style file.
The format this class understands is a very limited subset of
PostScript.
- Usage (subject to change):
- for name in Encoding(filename):
- whatever(name)
+ Usage (subject to change)::
+
+ for name in Encoding(filename):
+ whatever(name)
"""
__slots__ = ('encoding',)
Modified: trunk/matplotlib/lib/matplotlib/texmanager.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/texmanager.py 2008-05-22 19:58:22 UTC
(rev 5217)
+++ trunk/matplotlib/lib/matplotlib/texmanager.py 2008-05-22 21:01:40 UTC
(rev 5218)
@@ -6,31 +6,31 @@
Requirements:
- tex
-
- *Agg backends: dvipng
-
- PS backend: latex w/ psfrag, dvips, and Ghostscript 8.51
+* latex
+* \*Agg backends: dvipng
+* PS backend: latex w/ psfrag, dvips, and Ghostscript 8.51
(older versions do not work properly)
Backends:
- Only supported on *Agg and PS backends currently
+* \*Agg
+* PS
+* PDF
-
For raster output, you can get RGBA numpy arrays from TeX expressions
-as follows
+as follows::
texmanager = TexManager()
- s = r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!'
+ s = '\\TeX\\ is Number
$\\displaystyle\\sum_{n=1}^\\infty\\frac{-e^{i\pi}}{2^n}$!'
Z = self.texmanager.get_rgba(s, size=12, dpi=80, rgb=(1,0,0))
To enable tex rendering of all text in your matplotlib figure, set
text.usetex in your matplotlibrc file (http://matplotlib.sf.net/matplotlibrc)
-or include these two lines in your script:
-from matplotlib import rc
-rc('text', usetex=True)
+or include these two lines in your script::
+ from matplotlib import rc
+ rc('text', usetex=True)
+
"""
import copy, glob, md5, os, shutil, sys
@@ -55,7 +55,9 @@
raise RuntimeError('Could not obtain dvipng version')
+
class TexManager:
+
"""
Convert strings to dvi files using TeX, caching the results to a
working dir
@@ -155,6 +157,9 @@
r'\usepackage{textcomp}'])
def get_basefile(self, tex, fontsize, dpi=None):
+ """
+ returns a filename based on a hash of the string, fontsize, and dpi
+ """
s = ''.join([tex, self.get_font_config(), '%f'%fontsize,
self.get_custom_preamble(), str(dpi or '')])
# make sure hash is consistent for all strings, regardless of encoding:
@@ -162,7 +167,7 @@
return os.path.join(self.texcache, md5.md5(bytes).hexdigest())
def get_font_config(self):
- "Reinitializes self if rcParams self depends on have changed."
+ """Reinitializes self if relevant rcParams on have changed."""
if self._rc_cache is None:
self._rc_cache = dict([(k,None) for k in self._rc_cache_keys])
changed = [par for par in self._rc_cache_keys if rcParams[par] != \
@@ -181,12 +186,16 @@
return self._fontconfig
def get_font_preamble(self):
+ """
+ returns a string containing font configuration for the tex preamble
+ """
return self._font_preamble
def get_custom_preamble(self):
+ """returns a string containing user additions to the tex preamble"""
return '\n'.join(rcParams['text.latex.preamble'])
- def get_shell_cmd(self, *args):
+ def _get_shell_cmd(self, *args):
"""
On windows, changing directories can be complicated by the presence of
multiple drives. get_shell_cmd deals with this issue.
@@ -199,6 +208,11 @@
return ' && '.join(command)
def make_tex(self, tex, fontsize):
+ """
+ Generate a tex file to render the tex string at a specific font size
+
+ returns the file name
+ """
basefile = self.get_basefile(tex, fontsize)
texfile = '%s.tex'%basefile
fh = file(texfile, 'w')
@@ -241,14 +255,18 @@
return texfile
def make_dvi(self, tex, fontsize):
+ """
+ generates a dvi file containing latex's layout of tex string
+ returns the file name
+ """
basefile = self.get_basefile(tex, fontsize)
dvifile = '%s.dvi'% basefile
if DEBUG or not os.path.exists(dvifile):
texfile = self.make_tex(tex, fontsize)
outfile = basefile+'.output'
- command = self.get_shell_cmd('cd "%s"'% self.texcache,
+ command = self._get_shell_cmd('cd "%s"'% self.texcache,
'latex -interaction=nonstopmode %s > "%s"'\
%(os.path.split(texfile)[-1], outfile))
mpl.verbose.report(command, 'debug')
@@ -267,6 +285,11 @@
return dvifile
def make_png(self, tex, fontsize, dpi):
+ """
+ generates a png file containing latex's rendering of tex string
+
+ returns the filename
+ """
basefile = self.get_basefile(tex, fontsize, dpi)
pngfile = '%s.png'% basefile
@@ -274,7 +297,7 @@
if DEBUG or not os.path.exists(pngfile):
dvifile = self.make_dvi(tex, fontsize)
outfile = basefile+'.output'
- command = self.get_shell_cmd('cd "%s"' % self.texcache,
+ command = self._get_shell_cmd('cd "%s"' % self.texcache,
'dvipng -bg Transparent -D %s -T tight -o \
"%s" "%s" > "%s"'%(dpi, os.path.split(pngfile)[-1],
os.path.split(dvifile)[-1], outfile))
@@ -292,14 +315,18 @@
return pngfile
def make_ps(self, tex, fontsize):
+ """
+ generates a postscript file containing latex's rendering of tex string
+ returns the file name
+ """
basefile = self.get_basefile(tex, fontsize)
psfile = '%s.epsf'% basefile
if DEBUG or not os.path.exists(psfile):
dvifile = self.make_dvi(tex, fontsize)
outfile = basefile+'.output'
- command = self.get_shell_cmd('cd "%s"'% self.texcache,
+ command = self._get_shell_cmd('cd "%s"'% self.texcache,
'dvips -q -E -o "%s" "%s" > "%s"'\
%(os.path.split(psfile)[-1],
os.path.split(dvifile)[-1], outfile))
@@ -317,6 +344,10 @@
return psfile
def get_ps_bbox(self, tex, fontsize):
+ """
+ returns a list containing the postscript bounding box for latex's
+ rendering of the tex string
+ """
psfile = self.make_ps(tex, fontsize)
ps = file(psfile)
for line in ps:
@@ -325,6 +356,7 @@
raise RuntimeError('Could not parse %s'%psfile)
def get_grey(self, tex, fontsize=None, dpi=None):
+ """returns the alpha channel"""
key = tex, self.get_font_config(), fontsize, dpi
alpha = self.grey_arrayd.get(key)
@@ -344,7 +376,7 @@
def get_rgba(self, tex, fontsize=None, dpi=None, rgb=(0,0,0)):
"""
- Return tex string as an rgba array
+ Returns latex's rendering of the tex string as an rgba array
"""
# dvipng assumes a constant background, whereas we want to
# overlay these rasters with antialiasing over arbitrary
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins