matplotlib.backends.backend_svg#

matplotlib.backends.backend_svg.FigureCanvas[source]#

alias ofFigureCanvasSVG

classmatplotlib.backends.backend_svg.FigureCanvasSVG(figure=None)[source]#

Bases:FigureCanvasBase

draw()[source]#

Render theFigure.

This method must walk the artist tree, even if no output is produced,because it triggers deferred work that users may want to accessbefore saving output to disk. For example computing limits,auto-limits, and tick values.

filetypes={'svg':'ScalableVectorGraphics','svgz':'ScalableVectorGraphics'}#
fixed_dpi=72#
get_default_filetype()[source]#

Return the default savefig file format as specified inrcParams["savefig.format"] (default:'png').

The returned string does not include a period. This method isoverridden in backends that only support a single file type.

print_svg(filename,*,bbox_inches_restore=None,metadata=None)[source]#
Parameters:
filenamestr or path-like or file-like

Output target; if a string, a file will be opened for writing.

metadatadict[str, Any], optional

Metadata in the SVG file defined as key-value pairs of strings,datetimes, or lists of strings, e.g.,{'Creator':'Mysoftware','Contributor':['Me','MyFriend'],'Title':'Awesome'}.

The standard keys and their value types are:

  • str:'Coverage','Description','Format','Identifier','Language','Relation','Source','Title', and'Type'.

  • str orlist of str:'Contributor','Creator','Keywords','Publisher', and'Rights'.

  • str,date,datetime, ortuple of same:'Date'. If anon-str, then it will be formatted as ISO 8601.

Values have been predefined for'Creator','Date','Format', and'Type'. They can be removed by setting themtoNone.

Information is encoded asDublin Core Metadata.

print_svgz(filename,**kwargs)[source]#
classmatplotlib.backends.backend_svg.RendererSVG(width,height,svgwriter,basename=None,image_dpi=72,*,metadata=None)[source]#

Bases:RendererBase

close_group(s)[source]#

Close a grouping element with labels.

Only used by the SVG renderer.

draw_gouraud_triangles(gc,triangles_array,colors_array,transform)[source]#

Draw a series of Gouraud triangles.

Parameters:
gcGraphicsContextBase

The graphics context.

triangles_array(N, 3, 2) array-like

Array ofN (x, y) points for the triangles.

colors_array(N, 3, 4) array-like

Array ofN RGBA colors for each point of the triangles.

transformTransform

An affine transform to apply to the points.

draw_image(gc,x,y,im,transform=None)[source]#

Draw an RGBA image.

Parameters:
gcGraphicsContextBase

A graphics context with clipping information.

xfloat

The distance in physical units (i.e., dots or pixels) from the lefthand side of the canvas.

yfloat

The distance in physical units (i.e., dots or pixels) from thebottom side of the canvas.

im(N, M, 4) array ofnumpy.uint8

An array of RGBA pixels.

transformAffine2DBase

If and only if the concrete backend is written such thatoption_scale_image returnsTrue, an affinetransformation (i.e., anAffine2DBase)may be passed todraw_image. The translation vector of thetransformation is given in physical units (i.e., dots or pixels).Note that the transformation does not overridex andy,and has to be appliedbefore translatingthe result byx andy (this can be accomplished by addingxandy to the translation vector defined bytransform).

draw_markers(gc,marker_path,marker_trans,path,trans,rgbFace=None)[source]#

Draw a marker at each ofpath's vertices (excluding control points).

The base (fallback) implementation makes multiple calls todraw_path.Backends may want to override this method in order to draw the markeronly once and reuse it multiple times.

Parameters:
gcGraphicsContextBase

The graphics context.

marker_pathPath

The path for the marker.

marker_transTransform

An affine transform applied to the marker.

pathPath

The locations to draw the markers.

transTransform

An affine transform applied to the path.

rgbFacecolor, optional
draw_path(gc,path,transform,rgbFace=None)[source]#

Draw aPath instance using the given affine transform.

draw_path_collection(gc,master_transform,paths,all_transforms,offsets,offset_trans,facecolors,edgecolors,linewidths,linestyles,antialiaseds,urls,offset_position,*,hatchcolors=None)[source]#

Draw a collection ofpaths.

Each path is first transformed by the corresponding entryinall_transforms (a list of (3, 3) matrices) and then bymaster_transform. They are then translated by the correspondingentry inoffsets, which has been first transformed byoffset_trans.

facecolors,edgecolors,linewidths,linestyles,antialiasedandhatchcolors are lists that set the corresponding properties.

Added in version 3.11:Allowhatchcolors to be specified.

offset_position is unused now, but the argument is kept forbackwards compatibility.

The base (fallback) implementation makes multiple calls todraw_path.Backends may want to override this in order to render each set ofpath data only once, and then reference that path multiple times withthe different offsets, colors, styles etc. The generator methods_iter_collection_raw_paths and_iter_collection are provided tohelp with (and standardize) the implementation across backends. Itis highly recommended to use those generators, so that changes to thebehavior ofdraw_path_collection can be made globally.

draw_text(gc,x,y,s,prop,angle,ismath=False,mtext=None)[source]#

Draw a text instance.

Parameters:
gcGraphicsContextBase

The graphics context.

xfloat

The x location of the text in display coords.

yfloat

The y location of the text baseline in display coords.

sstr

The text string.

propFontProperties

The font properties.

anglefloat

The rotation angle in degrees anti-clockwise.

ismathbool or "TeX"

If True, use mathtext parser.

mtextText

The original text object to be rendered.

Notes

Notes for backend implementers:

RendererBase.draw_text also supports passing "TeX" to theismathparameter to use TeX rendering, but this is not required for actualrendering backends, and indeed many builtin backends do not supportthis. Rather, TeX rendering is provided bydraw_tex.

finalize()[source]#
flipy()[source]#

Return whether y values increase from top to bottom.

Note that this only affects drawing of texts.

get_canvas_width_height()[source]#

Return the canvas width and height in display coords.

get_image_magnification()[source]#

Get the factor by which to magnify images passed todraw_image.Allows a backend to have images at a different resolution to otherartists.

get_text_width_height_descent(s,prop,ismath)[source]#

Get the width, height, and descent (offset from the bottom to the baseline), indisplay coords, of the strings withFontPropertiesprop.

Whitespace at the start and the end ofs is included in the reported width.

open_group(s,gid=None)[source]#

Open a grouping element with labels andgid (if set) as id.

Only used by the SVG renderer.

option_image_nocomposite()[source]#

Return whether image composition by Matplotlib should be skipped.

Raster backends should usually return False (letting the C-levelrasterizer take care of image composition); vector backends shouldusually returnnotrcParams["image.composite_image"].

option_scale_image()[source]#

Return whether arbitrary affine transformations indraw_image are supported (True for most vector backends).

classmatplotlib.backends.backend_svg.XMLWriter(file)[source]#

Bases:object

Parameters:
filewritable text file-like object
close(id)[source]#

Close open elements, up to (and including) the element identifiedby the given identifier.

Parameters:
id

Element identifier, as returned by thestart() method.

comment(comment)[source]#

Add a comment to the output stream.

Parameters:
commentstr

Comment text.

data(text)[source]#

Add character data to the output stream.

Parameters:
textstr

Character data.

element(tag,text=None,attrib={},**extra)[source]#

Add an entire element. This is the same as callingstart(),data(), andend() in sequence. Thetext argument can beomitted.

end(tag=None,indent=True)[source]#

Close the current element (opened by the most recent call tostart()).

Parameters:
tag

Element tag. If given, the tag must match the start tag. Ifomitted, the current element is closed.

indentbool, default: True
flush()[source]#

Flush the output stream.

start(tag,attrib={},**extra)[source]#

Open a new element. Attributes can be given as keywordarguments, or as a string/string dictionary. The method returnsan opaque identifier that can be passed to theclose()method, to close all open elements up to and including this one.

Parameters:
tag

Element tag.

attrib

Attribute dictionary. Alternatively, attributes can be given askeyword arguments.

Returns:
An element identifier.