| [ Web Proxy ] |
| Viewing: https://matplotlib.org/stable/api/_as_gen/../../gallery/mplot3d/../../api/backend_template_api.html | [Back] [Original] |
matplotlib.backends.backend_template#A fully functional, do-nothing backend intended as a template for backend writers. It is fully functional in that you can select it as a backend e.g. with
import matplotlib
matplotlib.use("template")
and your program will (should!) run without error, though no output is
produced. This provides a starting point for backend writers; you can
selectively implement drawing methods (draw_path,
draw_image, etc.) and slowly see your figure come to life
instead having to have a full-blown implementation before getting any results.
Copy this file to a directory outside the Matplotlib source tree, somewhere
where Python can import it (by adding the directory to your sys.path or by
packaging it as a normal Python package); if the backend is importable as
import my.backend you can then select it using
import matplotlib
matplotlib.use("module://my.backend")
If your backend implements support for saving figures (i.e. has a print_xyz method),
you can register it as the default handler for a given file type:
from matplotlib.backend_bases import register_backend
register_backend('xyz', 'my_backend', 'XYZ File Format')
...
plt.savefig("figure.xyz")
alias of FigureCanvasTemplate
Bases: FigureCanvasBase
The canvas the figure renders into. Calls the draw and print fig methods, creates the renderers, etc.
Note: GUI templates will want to connect events for button presses, mouse movements and key presses to functions that call the base class methods button_press_event, button_release_event, motion_notify_event, key_press_event, and key_release_event. See the implementations of the interactive backends for examples.
FigureA high-level Figure instance
Draw the figure using the renderer.
It is important that this method actually walk the artist tree even if not output is produced because this will trigger deferred work (like computing limits auto-limits and tick values) that users may want access to before saving to disk.
Return the default savefig file format as specified in
rcParams["savefig.format"] (default: 'png').
The returned string does not include a period. This method is overridden in backends that only support a single file type.
alias of FigureManagerTemplate
Write out format foo.
This method is normally called via Figure.savefig and
FigureCanvasBase.print_figure, which take care of setting the figure
facecolor, edgecolor, and dpi to the desired output values, and will
restore them to the original values. Therefore, print_foo does not
need to handle these settings.
alias of FigureManagerTemplate
Bases: FigureManagerBase
Helper class for pyplot mode, wraps everything up into a neat bundle.
For non-interactive backends, the base class is sufficient. For
interactive backends, see the documentation of the FigureManagerBase
class for the list of methods that can/should be overridden.
Bases: GraphicsContextBase
The graphics context provides the color, line styles, etc. See the cairo and postscript backends for examples of mapping the graphics context attributes (cap styles, join styles, line widths, colors) to a particular backend. In cairo this is done by wrapping a cairo.Context object and forwarding the appropriate calls to it using a dictionary mapping styles to gdk constants. In Postscript, all the work is done by the renderer, mapping line styles to postscript calls.
If it's more appropriate to do the mapping at the renderer level (as in the postscript backend), you don't need to override any of the GC methods. If it's more appropriate to wrap an instance (as in the cairo backend) and do the mapping here, you'll need to override several of the setter methods.
The base GraphicsContext stores colors as an RGB tuple on the unit interval, e.g., (0.5, 0.0, 1.0). You may need to map this to colors appropriate for your backend.
Bases: RendererBase
The renderer handles drawing/rendering operations.
This is a minimal do-nothing class that can be used to get started when
writing a new backend. Refer to backend_bases.RendererBase for
documentation of the methods.
Draw an RGBA image.
GraphicsContextBaseA graphics context with clipping information.
The distance in physical units (i.e., dots or pixels) from the left hand side of the canvas.
The distance in physical units (i.e., dots or pixels) from the bottom side of the canvas.
numpy.uint8An array of RGBA pixels.
Affine2DBaseIf and only if the concrete backend is written such that
option_scale_image returns True, an affine
transformation (i.e., an Affine2DBase) may be passed to
draw_image. The translation vector of the
transformation is given in physical units (i.e., dots or pixels).
Note that the transformation does not override x and y,
and has to be applied before translatingthe result by
x and y (this can be accomplished by adding x
and y to the translation vector defined by transform).
Draw a Path instance using the given affine transform.
Draw a text instance.
GraphicsContextBaseThe graphics context.
The x location of the text in display coords.
The y location of the text baseline in display coords.
The text string.
FontPropertiesThe font properties.
The rotation angle in degrees anti-clockwise.
If True, use mathtext parser.
TextThe original text object to be rendered.
Notes
Notes for backend implementers:
RendererBase.draw_text also supports passing "TeX" to the ismath
parameter to use TeX rendering, but this is not required for actual
rendering backends, and indeed many builtin backends do not support
this. Rather, TeX rendering is provided by draw_tex.
Return whether y values increase from top to bottom.
Note that this only affects drawing of texts.
Get the width, height, and descent (offset from the bottom to the baseline), in
display coords, of the string s with FontProperties prop.
Whitespace at the start and the end of s is included in the reported width.
Return an instance of a GraphicsContextBase.
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 * dpi/72
| Web Proxy Viewer | New URL | Original Page |