SVG

class svgwrite.container.SVG(insert=None, size=None, **extra)

A SVG document fragment consists of any number of SVG elements contained within an svg element.

An SVG document fragment can range from an empty fragment (i.e., no content inside of the svg element), to a very simple SVG document fragment containing a single SVG graphics element such as a rect, to a complex, deeply nested collection of container elements and graphics elements.

SVG.__init__(insert=None, size=None, **extra)
Parameters:
  • insert (2-tuple) – insert position (x, y)
  • size (2-tuple) – (width, height)
  • extra – additional SVG attributes as keyword-arguments
SVG.embed_stylesheet(content)

Add <style> tag to the defs section.

Parameters:content – style sheet content as string
Returns:Style object
SVG.embed_font(name, filename)

Embed font as base64 encoded data from font file.

Parameters:
  • name – font name
  • filename – file name of local stored font
SVG.embed_google_web_font(name, uri)

Embed font as base64 encoded data acquired from google fonts.

Parameters:

Attributes

SVG.defs

Defs container for referenced elements

adding SVG elements to defs:

svgobject.defs.add(element)

SVG Attributes

  • classstring

    assigns one or more css-class-names to an element

  • stylestring

    allows per-element css-style rules to be specified directly on a given element

  • externalResourcesRequiredbool

    False: if document rendering can proceed even if external resources are unavailable else: True

  • transform – use svgwrite.mixins.Transform interface

  • x<coordinate>insert parameter

    (Has no meaning or effect on Drawing .)

    The x-axis coordinate of one corner of the rectangular region into which an embedded svg element is placed.

    Default is '0'.

  • y<coordinate>insert parameter

    (Has no meaning or effect on Drawing .)

    The y-axis coordinate of one corner of the rectangular region into which an embedded svg element is placed.

    Default is '0'.

  • width<length>size parameter

    For outermost svg elements (Drawing), the intrinsic width of the SVG document fragment. For embedded svg elements, the width of the rectangular region into which the svg element is placed.

    A negative value is an error. A value of zero disables rendering of the element.

    Default is '100%'.

  • height<length>size parameter

    For outermost svg elements (Drawing), the intrinsic height of the SVG document fragment. For embedded svg elements, the height of the rectangular region into which the svg element is placed.

    A negative value is an error. A value of zero disables rendering of the element.

    Default is '100%'.

  • viewBoxsvgwrite.mixins.ViewBox interface

  • preserveAspectRatiosvgwrite.mixins.ViewBox interface

  • zoomAndPan'disable | magnify'

    Default is 'magnify'.

Note

do not set or change following SVG attributes: version, baseProfile, contentScriptType, contentStyleType