matplotlib.backends.backend_svg
#
- matplotlib.backends.backend_svg.FigureCanvas[source]#
alias of
FigureCanvasSVG
- classmatplotlib.backends.backend_svg.FigureCanvasSVG(figure=None)[source]#
Bases:
FigureCanvasBase
- draw()[source]#
Render the
Figure
.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 in
rcParams["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.
- classmatplotlib.backends.backend_svg.RendererSVG(width,height,svgwriter,basename=None,image_dpi=72,*,metadata=None)[source]#
Bases:
RendererBase
- draw_gouraud_triangles(gc,triangles_array,colors_array,transform)[source]#
Draw a series of Gouraud triangles.
- Parameters:
- gc
GraphicsContextBase
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.
- transform
Transform
An affine transform to apply to the points.
- gc
- draw_image(gc,x,y,im,transform=None)[source]#
Draw an RGBA image.
- Parameters:
- gc
GraphicsContextBase
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 of
numpy.uint8
An array of RGBA pixels.
- transform
Affine2DBase
If and only if the concrete backend is written such that
option_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).
- gc
- 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 to
draw_path
.Backends may want to override this method in order to draw the markeronly once and reuse it multiple times.
- draw_path(gc,path,transform,rgbFace=None)[source]#
Draw a
Path
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 to
draw_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:
- gc
GraphicsContextBase
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.
- prop
FontProperties
The font properties.
- anglefloat
The rotation angle in degrees anti-clockwise.
- ismathbool or "TeX"
If True, use mathtext parser.
- mtext
Text
The original text object to be rendered.
- gc
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
.
- flipy()[source]#
Return whether y values increase from top to bottom.
Note that this only affects drawing of texts.
- get_image_magnification()[source]#
Get the factor by which to magnify images passed to
draw_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 with
FontProperties
prop.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 return
notrcParams["image.composite_image"]
.
- option_scale_image()[source]#
Return whether arbitrary affine transformations in
draw_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 the
start()
method.
- element(tag,text=None,attrib={},**extra)[source]#
Add an entire element. This is the same as calling
start()
,data()
, andend()
in sequence. Thetext argument can beomitted.
- end(tag=None,indent=True)[source]#
Close the current element (opened by the most recent call to
start()
).- Parameters:
- tag
Element tag. If given, the tag must match the start tag. Ifomitted, the current element is closed.
- indentbool, default: True
- 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 the
close()
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.