386 lines (332 with data), 28.5 kB
@header@
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="matplotlib.html"><font color="#ffffff">matplotlib</font></a>.<a href="matplotlib.backends.html"><font color="#ffffff">backends</font></a>.backend_agg</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py">/usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py</a></font></td></tr></table>
<p><tt>An agg <a href="http://antigrain.com/">http://antigrain.com/</a> backend<br>
<br>
Features that are implemented<br>
<br>
* capstyles and join styles<br>
* dashes<br>
* linewidth <br>
* lines, rectangles, ellipses<br>
* clipping to a rectangle<br>
* output to RGBA and PNG<br>
* alpha blending<br>
* DPI scaling properly - everything scales properly (dashes, linewidths, etc)<br>
* draw polygon <br>
* freetype2 w/ ft2font<br>
<br>
TODO:<br>
<br>
* allow save to file handle<br>
<br>
* allow load from png<br>
<br>
* integrate screen dpi w/ ppi and text<br>
<br>
INSTALLING <br>
<br>
REQUIREMENTs<br>
<br>
python2.2+<br>
Numeric 22+<br>
agg2 (see below)<br>
freetype 2<br>
libpng<br>
libz<br>
<br>
Install AGG2 (cut and paste below into xterm should work)<br>
<br>
wget <a href="http://www.antigrain.com/agg2.tar.gz">http://www.antigrain.com/agg2.tar.gz</a><br>
tar xvfz agg2.tar.gz<br>
cd agg2<br>
make<br>
<br>
(Optional) if you want to make the examples:<br>
cd examples/X11<br>
make<br>
<br>
Installing backend_agg<br>
<br>
<br>
Edit setup.py: change aggsrc to point to the agg2 src tree and<br>
replace if 0: with if 1: in the backend_agg section<br>
<br>
Then just do the usual thing: python setup.py build<br>
<br>
Please let me know if you encounter build problems, and tell me<br>
platform, gcc version, etc... Currently the paths in setupext.py<br>
assume as linux like filesystem (eg X11 include dir, location of<br>
libttf, etcc) so you may need to tweak these<br>
<br>
Using agg backend<br>
<br>
python somefile.py -dAgg <br>
<br>
or<br>
<br>
import matplotlib<br>
matplotlib.use('Agg')</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="matplotlib.html">matplotlib</a><br>
</td><td width="25%" valign=top><a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="matplotlib.backend_bases.html#FigureCanvasBase">matplotlib.backend_bases.FigureCanvasBase</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="matplotlib.backends.backend_agg.html#FigureCanvasAgg">FigureCanvasAgg</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="matplotlib.backend_bases.html#RendererBase">matplotlib.backend_bases.RendererBase</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="matplotlib.backends.backend_agg.html#RendererAgg">RendererAgg</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="FigureCanvasAgg">class <strong>FigureCanvasAgg</strong></a>(<a href="matplotlib.backend_bases.html#FigureCanvasBase">matplotlib.backend_bases.FigureCanvasBase</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>The canvas the figure renders into. Calls the draw and print fig<br>
methods, creates the renderers, etc...<br>
<br>
Public attribute<br>
<br>
figure - A Figure instance<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="FigureCanvasAgg-buffer_rgba"><strong>buffer_rgba</strong></a>(self)</dt></dl>
<dl><dt><a name="FigureCanvasAgg-draw"><strong>draw</strong></a>(self)</dt><dd><tt>Draw the figure using the renderer</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-get_renderer"><strong>get_renderer</strong></a>(self)</dt></dl>
<dl><dt><a name="FigureCanvasAgg-print_figure"><strong>print_figure</strong></a>(self, filename, dpi<font color="#909090">=150</font>, facecolor<font color="#909090">='w'</font>, edgecolor<font color="#909090">='w'</font>, orientation<font color="#909090">='portrait'</font>)</dt><dd><tt>Render the figure to hardcopy. Set the figure patch face and<br>
edge colors. This is useful because some of the GUIs have a<br>
gray figure face color background and you'll probably want to<br>
override this on hardcopy<br>
<br>
If the extension matches PNG, write a PNG file<br>
<br>
If the extension matches BMP or RAW, write an RGBA bitmap file<br>
<br>
If filename is a fileobject, write png to file object (thus<br>
you can, for example, write the png to stdout</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-tostring_argb"><strong>tostring_argb</strong></a>(self)</dt></dl>
<dl><dt><a name="FigureCanvasAgg-tostring_rgb"><strong>tostring_rgb</strong></a>(self)</dt></dl>
<hr>
Methods inherited from <a href="matplotlib.backend_bases.html#FigureCanvasBase">matplotlib.backend_bases.FigureCanvasBase</a>:<br>
<dl><dt><a name="FigureCanvasAgg-__init__"><strong>__init__</strong></a>(self, figure)</dt></dl>
<dl><dt><a name="FigureCanvasAgg-button_press_event"><strong>button_press_event</strong></a>(self, x, y, button, guiEvent<font color="#909090">=None</font>)</dt><dd><tt>Backend derived classes should call this function on any mouse<br>
button press. x,y are the canvas coords: 0,0 is lower, left.<br>
button and key are as defined in MouseEvent</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-button_release_event"><strong>button_release_event</strong></a>(self, x, y, button, guiEvent<font color="#909090">=None</font>)</dt><dd><tt>Backend derived classes should call this function on any mouse<br>
button release. x,y are the canvas coords: 0,0 is lower, left.<br>
button and key are as defined in MouseEvent</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-draw_cursor"><strong>draw_cursor</strong></a>(self, event)</dt><dd><tt>Draw a cursor in the event.axes if inaxes is not None. Use<br>
native GUI drawing for efficiency if possible</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-draw_idle"><strong>draw_idle</strong></a>(self, *args, **kwargs)</dt><dd><tt>draw only if idle; defaults to draw but backends can overrride</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-key_press_event"><strong>key_press_event</strong></a>(self, key, guiEvent<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="FigureCanvasAgg-key_release_event"><strong>key_release_event</strong></a>(self, key, guiEvent<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="FigureCanvasAgg-motion_notify_event"><strong>motion_notify_event</strong></a>(self, x, y, guiEvent<font color="#909090">=None</font>)</dt><dd><tt>Backend derived classes should call this function on any mouse<br>
button release. x,y are the canvas coords: 0,0 is lower, left.<br>
button and key are as defined in MouseEvent</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-mpl_connect"><strong>mpl_connect</strong></a>(self, s, func)</dt><dd><tt>Connect event with string s to func. The signature of func is<br>
<br>
def func(event)<br>
<br>
where event is a MplEvent. The following events are recognized<br>
<br>
'key_press_event' <br>
'button_press_event' <br>
'button_release_event' <br>
'motion_notify_event' <br>
<br>
For the three events above, if the mouse is over the axes,<br>
the variable event.inaxes will be set to the axes it is over,<br>
and additionally, the variables event.xdata and event.ydata<br>
will be defined. This is the mouse location in data coords.<br>
See backend_bases.MplEvent.<br>
<br>
return value is a connection id that can be used with<br>
mpl_disconnect</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-mpl_disconnect"><strong>mpl_disconnect</strong></a>(self, cid)</dt><dd><tt>Connect s to func. return an id that can be used with disconnect<br>
Method should return None</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-switch_backends"><strong>switch_backends</strong></a>(self, FigureCanvasClass)</dt><dd><tt>instantiate an instance of FigureCanvasClass<br>
<br>
This is used for backend switching, eg, to instantiate a<br>
FigureCanvasPS from a FigureCanvasGTK. Note, deep copying is<br>
not done, so any changes to one of the instances (eg, setting<br>
figure size or line props), will be reflected in the other</tt></dd></dl>
<hr>
Data and other attributes inherited from <a href="matplotlib.backend_bases.html#FigureCanvasBase">matplotlib.backend_bases.FigureCanvasBase</a>:<br>
<dl><dt><strong>events</strong> = ('key_press_event', 'key_release_event', 'button_press_event', 'button_release_event', 'motion_notify_event')</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="RendererAgg">class <strong>RendererAgg</strong></a>(<a href="matplotlib.backend_bases.html#RendererBase">matplotlib.backend_bases.RendererBase</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>The renderer handles all the drawing primitives using a graphics<br>
context instance that controls the colors/styles<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="RendererAgg-__init__"><strong>__init__</strong></a>(self, width, height, dpi)</dt></dl>
<dl><dt><a name="RendererAgg-buffer_rgba"><strong>buffer_rgba</strong></a>(self)</dt></dl>
<dl><dt><a name="RendererAgg-clear"><strong>clear</strong></a>(self)</dt></dl>
<dl><dt><a name="RendererAgg-draw_arc"><strong>draw_arc</strong></a>(self, gcEdge, rgbFace, x, y, width, height, angle1, angle2)</dt><dd><tt>Draw an arc centered at x,y with width and height and angles<br>
from 0.0 to 360.0<br>
<br>
If rgbFace is not None, fill the rectangle with that color. gcEdge<br>
is a GraphicsContext instance<br>
<br>
Currently, I'm only supporting ellipses, ie angle args are<br>
ignored</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_line"><strong>draw_line</strong></a>(self, gc, x1, y1, x2, y2)</dt><dd><tt>x and y are equal length arrays, draw lines connecting each<br>
point in x, y</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_mathtext"><strong>draw_mathtext</strong></a>(self, gc, x, y, s, prop, angle)</dt><dd><tt>Draw the math text using matplotlib.mathtext</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_point"><strong>draw_point</strong></a>(self, gc, x, y)</dt><dd><tt>Draw a single point at x,y</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_tex"><strong>draw_tex</strong></a>(self, gc, x, y, s, prop, angle)</dt></dl>
<dl><dt><a name="RendererAgg-draw_text"><strong>draw_text</strong></a>(self, gc, x, y, s, prop, angle, ismath)</dt><dd><tt>Render the text</tt></dd></dl>
<dl><dt><a name="RendererAgg-get_canvas_width_height"><strong>get_canvas_width_height</strong></a>(self)</dt><dd><tt>return the canvas width and height in display coords</tt></dd></dl>
<dl><dt><a name="RendererAgg-get_text_width_height"><strong>get_text_width_height</strong></a>(self, s, prop, ismath, rgb<font color="#909090">=(0, 0, 0)</font>)</dt><dd><tt>get the width and height in display coords of the string s<br>
with FontPropertry prop<br>
<br>
# passing rgb is a little hack to make cacheing in the<br>
# texmanager more efficient. It is not meant to be used<br>
# outside the backend</tt></dd></dl>
<dl><dt><a name="RendererAgg-points_to_pixels"><strong>points_to_pixels</strong></a>(self, points)</dt><dd><tt>convert point measures to pixes using dpi and the pixels per<br>
inch of the display</tt></dd></dl>
<dl><dt><a name="RendererAgg-tostring_argb"><strong>tostring_argb</strong></a>(self)</dt></dl>
<dl><dt><a name="RendererAgg-tostring_rgb"><strong>tostring_rgb</strong></a>(self)</dt></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>debug</strong> = 1</dl>
<hr>
Methods inherited from <a href="matplotlib.backend_bases.html#RendererBase">matplotlib.backend_bases.RendererBase</a>:<br>
<dl><dt><a name="RendererAgg-blit"><strong>blit</strong></a>(self)</dt><dd><tt>blit the cached copy of the canvas, to be used in conjunction<br>
with blit in support of animation</tt></dd></dl>
<dl><dt><a name="RendererAgg-cache"><strong>cache</strong></a>(self)</dt><dd><tt>save a copy of the canvas, to be used in conjunction with blit<br>
in support of animation</tt></dd></dl>
<dl><dt><a name="RendererAgg-close_group"><strong>close_group</strong></a>(self, s)</dt><dd><tt>close a grouping element with label s<br>
Is only currently used by backend_svg</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_image"><strong>draw_image</strong></a>(self, x, y, im, origin, bbox)</dt><dd><tt>Draw the Image instance into the current axes; x is the<br>
distance in pixels from the left hand side of the canvas. y is<br>
the distance from the origin. That is, if origin is upper, y<br>
is the distance from top. If origin is lower, y is the<br>
distance from bottom<br>
<br>
origin is 'upper' or 'lower'<br>
<br>
bbox is a matplotlib.transforms.BBox instance for clipping, or<br>
None</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_line_collection"><strong>draw_line_collection</strong></a>(self, segments, transform, clipbox, colors, linewidths, linestyle, antialiaseds, offsets, transOffset)</dt><dd><tt>This is a function for optimized line drawing. If you need to draw<br>
many line segments with similar properties, it is faster to avoid the<br>
overhead of all the object creation etc. The lack of total<br>
configurability is compensated for with efficiency. Hence we don't use<br>
a GC and many of the line props it supports. See<br>
matplotlib.collections for more details.<br>
<br>
segments is a sequence of ( line0, line1, line2), where linen =<br>
(x0, y0), (x1, y1), ... (xm, ym). Each line can be a<br>
different length<br>
<br>
transform is used to Transform the lines<br>
<br>
clipbox is a xmin, ymin, width, height clip rect<br>
<br>
colors is a tuple of RGBA tuples<br>
<br>
linewidths is a tuple of linewidths<br>
*** really should be called 'dashes' not 'linestyle', since<br>
we call gc.set_dashes() not gc.set_linestyle() ***<br>
<br>
linestyle is an (offset, onoffseq) tuple or None,None for solid<br>
<br>
antialiseds is a tuple of ones or zeros indicating whether the<br>
segment should be aa or not<br>
<br>
offsets, if not None, is a list of x,y offsets to translate the lines<br>
by after transform is used to transform the offset coords<br>
<br>
This function could be overridden in the backend to possibly implement<br>
faster drawing, but it is already much faster than using <a href="#RendererAgg-draw_lines">draw_lines</a>()<br>
by itself.</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_lines"><strong>draw_lines</strong></a>(self, gc, x, y, transform<font color="#909090">=None</font>)</dt><dd><tt>x and y are equal length arrays, draw lines connecting each<br>
point in x, y</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_poly_collection"><strong>draw_poly_collection</strong></a>(self, verts, transform, clipbox, facecolors, edgecolors, linewidths, antialiaseds, offsets, transOffset)</dt><dd><tt>Draw a polygon collection<br>
<br>
verts are a sequence of polygon vectors, where each polygon<br>
vector is a sequence of x,y tuples of vertices<br>
<br>
facecolors and edgecolors are a sequence of RGBA tuples<br>
linewidths are a sequence of linewidths<br>
antialiaseds are a sequence of 0,1 integers whether to use aa</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_polygon"><strong>draw_polygon</strong></a>(self, gc, rgbFace, points)</dt><dd><tt>Draw a polygon using the GraphicsContext instance gc.<br>
points is a len vertices tuple, each element<br>
giving the x,y coords a vertex<br>
<br>
If the color rgbFace is not None, fill the polygon with it</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_rectangle"><strong>draw_rectangle</strong></a>(self, gcEdge, rgbFace, x, y, width, height)</dt><dd><tt>Draw a non-filled rectangle using the GraphicsContext instance gcEdge,<br>
with lower left at x,y with width and height.<br>
<br>
If rgbFace is not None, fill the rectangle with it.</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_regpoly_collection"><strong>draw_regpoly_collection</strong></a>(self, clipbox, offsets, transOffset, verts, sizes, facecolors, edgecolors, linewidths, antialiaseds)</dt><dd><tt>Draw a regular poly collection<br>
<br>
offsets - is a sequence is x,y tuples<br>
transOffset - maps this to display coords<br>
<br>
verts - are the vertices of the regular polygon at the origin<br>
<br>
sizes are the area of the circle that circumscribes the<br>
polygon in points^2<br>
<br>
facecolors and edgecolors are a sequence of RGBA tuples<br>
linewidths are a sequence of linewidths<br>
antialiaseds are a sequence of 0,1 integers whether to use aa</tt></dd></dl>
<dl><dt><a name="RendererAgg-flipy"><strong>flipy</strong></a>(self)</dt><dd><tt>return true if y small numbers are top for renderer<br>
Is used for drawing text (text.py) and images (image.py) only</tt></dd></dl>
<dl><dt><a name="RendererAgg-get_text_extent"><strong>get_text_extent</strong></a>(self, text)</dt><dd><tt>Get the text extent in window coords</tt></dd></dl>
<dl><dt><a name="RendererAgg-new_gc"><strong>new_gc</strong></a>(self)</dt><dd><tt>Return an instance of a GraphicsContextBase</tt></dd></dl>
<dl><dt><a name="RendererAgg-open_group"><strong>open_group</strong></a>(self, s)</dt><dd><tt>open a grouping element with label s<br>
Is only currently used by backend_svg</tt></dd></dl>
<dl><dt><a name="RendererAgg-strip_math"><strong>strip_math</strong></a>(self, s)</dt></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-FT2Font"><strong>FT2Font</strong></a>(...)</dt><dd><tt>FT2Font</tt></dd></dl>
<dl><dt><a name="-array"><strong>array</strong></a>(...)</dt><dd><tt><a href="#-array">array</a>(sequence, typecode=None, copy=1, savespace=0) will return a new array formed from the given (potentially nested) sequence with type given by typecode. If no typecode is given, then the type will be determined as the minimum type required to hold the objects in sequence. If copy is zero and sequence is already an array, a reference will be returned. If savespace is nonzero, the new array will maintain its precision in operations.</tt></dd></dl>
<dl><dt><a name="-fromarray"><strong>fromarray</strong></a>(...)</dt><dd><tt>fromarray</tt></dd></dl>
<dl><dt><a name="-new_figure_manager"><strong>new_figure_manager</strong></a>(num, *args, **kwargs)</dt><dd><tt>Create a new figure manager instance</tt></dd></dl>
<dl><dt><a name="-zeros"><strong>zeros</strong></a>(...)</dt><dd><tt><a href="#-zeros">zeros</a>((d1,...,dn),typecode='l',savespace=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero. If savespace is nonzero the array will be a spacesaver array.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>Float</strong> = 'd'<br>
<strong>backend_version</strong> = 'v2.2'<br>
<strong>division</strong> = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)<br>
<strong>fontManager</strong> = <matplotlib.font_manager.FontManager instance><br>
<strong>verbose</strong> = <matplotlib.Verbose instance></td></tr></table>
@footer@