Path

class svgwrite.path.Path(d=None, **extra)

The <path> element represent the outline of a shape which can be filled, stroked, used as a clipping path, or any combination of the three.

Path.__init__(d=None, **extra)
Parameters:
  • d (iterable) – coordinates, length and commands
  • attribs (dict) – additional SVG attributes
  • extra – additional SVG attributes as keyword-arguments

Attributes

commands

list – the command and coordinate stack

Methods

Path.push(*elements)

Push commands and coordinates onto the command stack.

Parameters:elements (iterable) – coordinates, length and commands
Path.push_arc(target, rotation, r, large_arc=True, angle_dir='+', absolute=False)

Helper function for the elliptical-arc command.

see SVG-Reference: http://www.w3.org/TR/SVG11/paths.html#PathData

Parameters:
  • target (2-tuple) – coordinate of the arc end point
  • rotation (number) – x-axis-rotation of the ellipse in degrees
  • r (number|2-tuple) – radii rx, ry when r is a 2-tuple or rx=ry=r if r is a number
  • large_arc (bool) – draw the arc sweep of greater than or equal to 180 degrees (large-arc-flag)
  • angle_dir'+|-' '+' means the arc will be drawn in a “positive-angle” direction (sweep-flag)
  • absolute (bool) – indicates that target coordinates are absolute else they are relative to the current point

Path Commands

Uppercase commands indicates absolute coordinates, lowercase commands indicates relative coordinates

  • horizontal-line ‘h’, ‘H’ x+

    Draws a horizontal line from the current point (cpx, cpy) to (x, cpy).

  • vertical-line ‘v’, ‘V’ y+

    Draws a vertical line from the current point (cpx, cpy) to (cpx, y).

  • line ‘l’, ‘L’ (x y)+

    Draw a line from the current point to the given (x,y) coordinate.

  • moveto ‘m’, ‘M’ (x y)+

    Start a new sub-path at the given (x,y) coordinate. If a moveto is followed by multiple pairs of coordinates, the subsequent pairs are treated as implicit lineto commands. Hence, implicit lineto commands will be relative if the moveto is relative, and absolute if the moveto is absolute. If a relative moveto (m) appears as the first element of the path, then it is treated as a pair of absolute coordinates. In this case, subsequent pairs of coordinates are treated as relative even though the initial moveto is interpreted as an absolute moveto.

  • cubic-bezier-curve ‘c’, ‘C’ (x1 y1 x2 y2 x y)+

    Draws a cubic Bézier curve from the current point to (x,y) using (x1,y1) as the control point at the beginning of the curve and (x2,y2) as the control point at the end of the curve.

  • smooth-cubic-bezier-curve ‘s’, ‘S’ (x2 y2 x y)+

    Draws a cubic Bézier curve from the current point to (x,y). The first control point is assumed to be the reflection of the second control point on the previous command relative to the current point. (If there is no previous command or if the previous command was not an C, c, S or s, assume the first control point is coincident with the current point.) (x2,y2) is the second control point (i.e., the control point at the end of the curve).

  • quadratic-bezier-curve ‘q’, ‘Q’ (x1 y1 x y)+

    Draws a quadratic Bézier curve from the current point to (x,y) using (x1,y1) as the control point.

  • smooth-quadratic-bezier-curve ‘t’, ‘T’ (x y)+

    Draws a quadratic Bézier curve from the current point to (x,y). The control point is assumed to be the reflection of the control point on the previous command relative to the current point. (If there is no previous command or if the previous command was not a Q, q, T or t, assume the control point is coincident with the current point.)

  • elliptical-arc ‘a’, ‘A’ (rx ry x-axis-rotation large-arc-flag sweep-flag x y)+

    Draws an elliptical arc from the current point to (x, y). The size and orientation of the ellipse are defined by two radii (rx, ry) and an x-axis-rotation, which indicates how the ellipse as a whole is rotated relative to the current coordinate system. The center (cx, cy) of the ellipse is calculated automatically to satisfy the constraints imposed by the other parameters. large-arc-flag and sweep-flag contribute to the automatic calculations and help determine how the arc is drawn.

  • ‘z’, ‘Z’

    close current subpath

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 methods

  • pathLength<number>

    the pathLength attribute can be used to provide the author’s computation of the total length of the path so that the user agent can scale distance-along-a-path computations by the ratio of ‘pathLength’ to the user agent’s own computed value for total path length. A “moveto” operation within a ‘path’ element is defined to have zero length.

  • dstring

    The definition of the outline of a shape, use push-method to add commands and coordinates