matplotlib.backends.backend_agg
¶An agg http://antigrain.com/ backend
Features that are implemented
- capstyles and join styles
- dashes
- linewidth
- lines, rectangles, ellipses
- clipping to a rectangle
- output to RGBA and PNG, optionally JPEG and TIFF
- alpha blending
- DPI scaling properly - everything scales properly (dashes, linewidths, etc)
- draw polygon
- freetype2 w/ ft2font
TODO:
- integrate screen dpi w/ ppi and text
matplotlib.backends.backend_agg.
FigureCanvas
¶matplotlib.backends.backend_agg.
FigureCanvasAgg
(figure)[source]¶Bases: matplotlib.backend_bases.FigureCanvasBase
The canvas the figure renders into. Calls the draw and print fig methods, creates the renderers, etc...
Attributes: |
|
---|
buffer_rgba
(self)[source]¶Get the image as a memoryview to the renderer's buffer.
draw
must be called at least once before this function will work and
to update the renderer for any subsequent changes to the Figure.
Returns: |
|
---|
print_jpeg
(self, filename_or_obj, *args, dryrun=False, pil_kwargs=None, **kwargs)¶Write the figure to a JPEG file.
Parameters: |
|
---|---|
Other Parameters: |
|
print_jpg
(self, filename_or_obj, *args, dryrun=False, pil_kwargs=None, **kwargs)[source]¶Write the figure to a JPEG file.
Parameters: |
|
---|---|
Other Parameters: |
|
print_png
(self, filename_or_obj, *args, metadata=None, pil_kwargs=None, **kwargs)[source]¶Write the figure to a PNG file.
Parameters: |
|
---|
print_rgba
(self, filename_or_obj, *args, **kwargs)¶print_tiff
(self, filename_or_obj, *args, dryrun=False, pil_kwargs=None, **kwargs)¶matplotlib.backends.backend_agg.
RendererAgg
(width, height, dpi)[source]¶Bases: matplotlib.backend_bases.RendererBase
The renderer handles all the drawing primitives using a graphics context instance that controls the colors/styles
draw_path
(self, gc, path, transform, rgbFace=None)[source]¶Draws a Path
instance using the
given affine transform.
draw_text
(self, gc, x, y, s, prop, angle, ismath=False, mtext=None)[source]¶Draw the text instance.
Parameters: |
|
---|
Notes
backend implementers note
When you are trying to determine if you have gotten your bounding box right (which is what enables the text layout/alignment to work properly), it helps to change the line in text.py:
if 0: bbox_artist(self, renderer)
to if 1, and then the actual bounding box will be plotted along with your text.
get_text_width_height_descent
(self, s, prop, ismath)[source]¶Get the width, height, and descent (offset from the bottom
to the baseline), in display coords, of the string s with
FontProperties
prop
lock
= <unlocked _thread.RLock object owner=0 count=0>¶option_image_nocomposite
(self)[source]¶Return whether image composition by Matplotlib should be skipped.
Raster backends should usually return False (letting the C-level
rasterizer take care of image composition); vector backends should
usually return not rcParams["image.composite_image"]
.
option_scale_image
(self)[source]¶Return whether arbitrary affine transformations in draw_image()
are supported (True for most vector backends).
points_to_pixels
(self, points)[source]¶Convert points to display units.
You need to override this function (unless your backend doesn't have a dpi, e.g., postscript or svg). Some imaging systems assume some value for pixels per inch:
points to pixels = points * pixels_per_inch/72.0 * dpi/72.0
Parameters: |
|
---|---|
Returns: |
|
restore_region
(self, region, bbox=None, xy=None)[source]¶Restore the saved region. If bbox (instance of BboxBase, or its extents) is given, only the region specified by the bbox will be restored. xy (a pair of floats) optionally specifies the new position (the LLC of the original region, not the LLC of the bbox) where the region will be restored.
>>> region = renderer.copy_from_bbox()
>>> x1, y1, x2, y2 = region.get_extents()
>>> renderer.restore_region(region, bbox=(x1+dx, y1, x2, y2),
... xy=(x1-dx, y1))
stop_filter
(self, post_processing)[source]¶Save the plot in the current canvas as a image and apply the post_processing function.
- def post_processing(image, dpi):
- # ny, nx, depth = image.shape # image (numpy array) has RGBA channels and has a depth of 4. ... # create a new_image (numpy array of 4 channels, size can be # different). The resulting image may have offsets from # lower-left corner of the original image return new_image, offset_x, offset_y
The saved renderer is restored and the returned image from post_processing is plotted (using draw_image) on it.