258 lines (232 with data), 17.1 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="/matplotlib/backends/backend_agg.py">/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>
* freetype1<br>
<br>
TODO:<br>
<br>
* use ttf manager to get font - right now I just use Vera<br>
* freetype2<br>
<br>
INSTALLING <br>
<br>
REQUIREMENTs<br>
<br>
python2.2+<br>
Numeric 22+<br>
agg2 (see below)<br>
freetype 1<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>
Grab the latest CVS:<br>
<br>
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/matplotlib login <br>
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/matplotlib co matplotlib<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')<br>
<br>
TODO:<br>
<br>
* implement ttf font manager<br>
<br>
* allow save to file handle<br>
<br>
* allow load from png<br>
<br>
<br>
Errors: running python2.2 on bace.bsd<br>
<br>
from _backend_agg import <a href="#RendererAgg">RendererAgg</a> as _RendererAgg, Font<br>
ImportError: /usr/lib/python2.2/site-packages/matplotlib/backends/_backend_agg.so: undefined symbol: __gxx_personality_v0</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="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><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-draw"><strong>draw</strong></a>(self)</dt><dd><tt>Draw the figure using the renderer</tt></dd></dl>
<dl><dt><a name="FigureCanvasAgg-print_figure"><strong>print_figure</strong></a>(self, filename, dpi<font color="#909090">=300</font>, facecolor<font color="#909090">='w'</font>, edgecolor<font color="#909090">='w'</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>
Here is an example PIL script to read and sisplay an RGBA file<br>
created by backend_agg<br>
<br>
import Image<br>
<br>
fname = "somefile.rgba"<br>
s = file(fname).read()<br>
<br>
M,N = 576, 432 # the image dimensions<br>
im = Image.fromstring("RGBA", (M,N), s)<br>
im.show()</tt></dd></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-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>
</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-compute_text_offsets"><strong>compute_text_offsets</strong></a>(self, t, props)</dt><dd><tt>Return the (x,y) offsets to adjust for the alignment<br>
specifications</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_arc"><strong>draw_arc</strong></a>(self, gcEdge, gcFace, 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 gcFace is not None, fill the rectangle with it. 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_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_text"><strong>draw_text</strong></a>(self, gc, x, y, t)</dt><dd><tt>Render the text using the RendererPaint instance</tt></dd></dl>
<dl><dt><a name="RendererAgg-get_agg_color"><strong>get_agg_color</strong></a>(self, rgb)</dt><dd><tt>returns an agg color object based on the given rgb tuple</tt></dd></dl>
<dl><dt><a name="RendererAgg-get_text_extent"><strong>get_text_extent</strong></a>(self, t)</dt><dd><tt>Return the ink extent of the text as Bound2D instance</tt></dd></dl>
<dl><dt><a name="RendererAgg-get_text_scale"><strong>get_text_scale</strong></a>(self)</dt><dd><tt>Return the scale factor for fontsize taking screendpi and pixels per<br>
inch into account</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>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>fontd</strong> = {}</dl>
<dl><dt><strong>offsetd</strong> = {}</dl>
<hr>
Methods inherited from <a href="matplotlib.backend_bases.html#RendererBase">matplotlib.backend_bases.RendererBase</a>:<br>
<dl><dt><a name="RendererAgg-draw_lines"><strong>draw_lines</strong></a>(self, gc, x, y)</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_polygon"><strong>draw_polygon</strong></a>(self, gcEdge, gcFace, points)</dt><dd><tt>Draw a polygon. points is a len vertices tuple, each element<br>
giving the x,y coords a vertex<br>
<br>
If gcFace is not None, fill the rectangle with it. gcEdge<br>
is a GraphicsContext instance</tt></dd></dl>
<dl><dt><a name="RendererAgg-draw_rectangle"><strong>draw_rectangle</strong></a>(self, gcEdge, gcFace, x, y, width, height)</dt><dd><tt>Draw a rectangle with lower left at x,y with width and height.<br>
<br>
If gcFace is not None, fill the rectangle with it. gcEdge<br>
is a GraphicsContext instance</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>
</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="-Font"><strong>Font</strong></a>(...)</dt><dd><tt><a href="#-Font">Font</a>(filename, size = 12, rotate = 0)<br>
<br>
Load the named font and return the font object</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="-new_figure_manager"><strong>new_figure_manager</strong></a>(num, *args)</dt><dd><tt>Create a new figure manager instance</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>False</strong> = False<br>
<strong>Float</strong> = 'd'<br>
<strong>PIXELS_PER_INCH</strong> = 96<br>
<strong>TEMPFONTCONST</strong> = '/usr/local/share/matplotlib/Vera.ttf'<br>
<strong>True</strong> = True<br>
<strong>division</strong> = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)</td></tr></table>
@footer@