Segment Drawing Primitives

Schemdraw drawing segments.

Each element is made up of one or more segments that define drawing primitives.

class schemdraw.segments.Segment(path, color=None, lw=None, ls=None, capstyle=None, joinstyle=None, fill=None, arrow=None, arrowwidth=0.15, arrowlength=0.25, clip=None, zorder=None, visible=True)

A segment path

Parameters:
  • path (Sequence[XY]) – List of (x,y) coordinates making the path

  • color (Optional[str | tuple[float, float, float]]) – Color for this segment

  • lw (Optional[float]) – Line width for the segment

  • ls (Optional[Linestyle]) – Line style for the segment ‘-’, ‘–’, ‘:’, etc.

  • capstyle (Optional[Capstyle]) – Capstyle for the segment: ‘butt’, ‘round’, ‘square’, (‘projecting’)

  • joinstyle (Optional[Joinstyle]) – Joinstyle for the segment: ‘round’, ‘miter’, or ‘bevel’

  • fill (Optional[str]) – Color to fill if path is closed

  • arrow (Optional[str]) – Arrowhead specifier, such as ‘->’, ‘<-’, ‘<->’, ‘-o’, etc.

  • arrowwidth (float) – Width of arrowhead

  • arrowlength (float) – Length of arrowhead

  • clip (Optional[BBox]) – Bounding box to clip to

  • zorder (Optional[int]) – Z-order for segment

  • visible (bool) – Show the segment when drawn

doflip()

Vertically flip the element

Return type:

None

doreverse(centerx)

Reverse the path (flip horizontal about the center of the path)

Return type:

None

draw(fig, transform, **style)

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

Return type:

None

get_bbox()

Get bounding box (untransformed)

Returns:

(xmin, ymin, xmax, ymax)

Return type:

Bounding box limits

xform(transform, **style)

Return a new Segment that has been transformed to its global position

Parameters:
  • transform – Transformation to apply

  • style – Style parameters from Element to apply as default

Return type:

Segment

class schemdraw.segments.SegmentArc(center, width, height, theta1=35, theta2=-35, arrow=None, arrowwidth=0.15, arrowlength=0.25, angle=0, color=None, lw=None, ls=None, fill=None, clip=None, zorder=None, visible=True)

An elliptical arc drawing segment

Parameters:
  • center (XY) – Center of the arc ellipse

  • width (float) – Width of the arc ellipse

  • height (float) – Height of the arc ellipse

  • theta1 (float) – Starting angle in degrees

  • theta2 (float) – Ending angle in degrees

  • arrow (Optional[Arcdirection]) – Direction of arrowhead (‘cw’ or ‘ccw’)

  • angle (float) – Rotation of the ellipse defining the arc

  • color (Optional[str | tuple[float, float, float]]) – Color for this segment

  • lw (Optional[float]) – Line width for the segment

  • ls (Optional[Linestyle]) – Line style for the segment

  • clip (Optional[BBox]) – Bounding box to clip to

  • zorder (Optional[int]) – Z-order for segment

  • visible (bool) – Show the segment when drawn

doflip()

Vertically flip the element

Return type:

None

doreverse(centerx)

Reverse the path (flip horizontal about the centerx point)

Return type:

None

draw(fig, transform, **style)

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

Return type:

None

get_bbox()

Get bounding box (untransformed)

Return type:

BBox

Returns:

Bounding box limits (xmin, ymin, xmax, ymax)

xform(transform, **style)

Return a new Segment that has been transformed to its global position

Parameters:
  • transform – Transformation to apply

  • style – Style parameters from Element to apply as default

Return type:

SegmentArc

class schemdraw.segments.SegmentBezier(p, color=None, lw=None, ls=None, capstyle=None, arrow=None, arrowlength=0.25, arrowwidth=0.15, clip=None, zorder=None, visible=True)

Quadratic or Cubic Bezier curve segment

Parameters:
  • p (Sequence[XY]) – control points (3 or 4)

  • color (Optional[str | tuple[float, float, float]]) – Color for this segment

  • lw (Optional[float]) – Line width for the segment

  • ls (Optional[Linestyle]) – Line style for the segment ‘-’, ‘–’, ‘:’, etc.

  • capstyle (Optional[Capstyle]) – Capstyle for the segment: ‘butt’, ‘round’, ‘square’, (‘projecting’)

  • joinstyle – Joinstyle for the segment: ‘round’, ‘miter’, or ‘bevel’

  • fill – Color to fill if path is closed

  • arrow (Optional[str]) – Arrowhead specifier, such as ‘->’, ‘<-’, or ‘<->’

  • arrowwidth (float) – Width of arrowhead

  • arrowlength (float) – Length of arrowhead

  • clip (Optional[BBox]) – Bounding box to clip to

  • zorder (Optional[int]) – Z-order for segment

  • visible (bool) – Show the segment when drawn

doflip()

Vertically flip the element

Return type:

None

doreverse(centerx)

Reverse the path (flip horizontal about the centerx point)

Return type:

None

draw(fig, transform, **style)

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

Return type:

None

get_bbox()

Get bounding box (untransformed)

Return type:

BBox

Returns:

Bounding box limits (xmin, ymin, xmax, ymax)

xform(transform, **style)

Return a new Segment that has been transformed to its global position

Parameters:
  • transform – Transformation to apply

  • style – Style parameters from Element to apply as default

Return type:

SegmentBezier

class schemdraw.segments.SegmentCircle(center, radius, color=None, lw=None, ls=None, fill=None, clip=None, zorder=None, ref=None, visible=True)

A circle drawing segment

Parameters:
  • center (XY) – (x, y) center of the circle

  • radius (float) – Radius of the circle

  • color (Optional[str | tuple[float, float, float]]) – Color for this segment

  • lw (Optional[float]) – Line width for the segment

  • ls (Optional[Linestyle]) – Line style for the segment

  • fill (bool | str | None) – Color to fill if path is closed. True -> fill with element color.

  • clip (Optional[BBox]) – Bounding box to clip to

  • zorder (Optional[int]) – Z-order for segment

  • ref (Optional[EndRef]) – Flip reference [‘start’, ‘end’, None].

  • visible (bool) – Show the segment when drawn

doflip()

Flip the segment up/down

Return type:

None

doreverse(centerx)

Reverse the path (flip horizontal about the centerx point)

Return type:

None

draw(fig, transform, **style)

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

Return type:

None

get_bbox()

Get bounding box (untransformed)

Return type:

BBox

Returns:

Bounding box limits (xmin, ymin, xmax, ymax)

xform(transform, **style)

Return a new Segment that has been transformed to its global position

Parameters:
  • transform – Transformation to apply

  • style – Style parameters from Element to apply as default

Return type:

SegmentCircle’ | ‘SegmentArc

class schemdraw.segments.SegmentImage(image, xy=(0, 0), width=3, height=1, rotate=0, imgfmt=None, zorder=None)

PNG or SVG Image

doflip()

Vertically flip the element

Return type:

None

doreverse(centerx)

Reverse the image

Return type:

None

draw(fig, transform, **style)

Draw the image

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

Return type:

None

get_bbox()

Get bounding box (untransformed)

Return type:

BBox

Returns:

Bounding box limits (xmin, ymin, xmax, ymax)

xform(transform, **style)

Return a new Segment that has been transformed to its global position

Parameters:
  • transform – Transformation to apply

  • style – Style parameters from Element to apply as default

Return type:

SegmentImage

class schemdraw.segments.SegmentPath(path, color=None, lw=None, ls=None, capstyle=None, joinstyle=None, fill=None, clip=None, zorder=None, visible=True)

Segment defined like svg <path> element made of M, L, C, Q, Z, etc….

doflip()

Vertically flip the element

Return type:

None

doreverse(centerx)

Reverse the path (flip horizontal about the center of the path)

Return type:

None

draw(fig, transform, **style)

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

Return type:

None

get_bbox()

Get bounding box (untransformed)

Returns:

(xmin, ymin, xmax, ymax)

Return type:

Bounding box limits

xform(transform, **style)

Return a new SegmentPath that has been transformed to its global position

Parameters:
  • transform – Transformation to apply

  • style – Style parameters from Element to apply as default

Return type:

SegmentPath

class schemdraw.segments.SegmentPoly(verts, closed=True, cornerradius=0, color=None, fill=None, lw=None, ls=None, hatch=False, joinstyle=None, capstyle=None, clip=None, zorder=None, visible=True)

A polygon segment

Parameters:
  • xy – List of (x,y) coordinates making the polygon

  • closed (bool) – Draw a closed polygon (default True)

  • cornerradius (float) – Round the corners to this radius (0 for no rounding)

  • color (Optional[str | tuple[float, float, float]]) – Color for this segment

  • fill (Optional[str]) – Color to fill if path is closed

  • lw (Optional[float]) – Line width for the segment

  • ls (Optional[Linestyle]) – Line style for the segment

  • hatch (bool) – Show hatch lines

  • capstyle (Optional[Capstyle]) – Capstyle for the segment: ‘butt’, ‘round’, ‘square’, (‘projecting’)

  • joinstyle (Optional[Joinstyle]) – Joinstyle for the segment: ‘round’, ‘miter’, or ‘bevel’

  • clip (Optional[BBox]) – Bounding box to clip to

  • zorder (Optional[int]) – Z-order for segment

  • visible (bool) – Show the segment when drawn

doflip()

Vertically flip the element

Return type:

None

doreverse(centerx)

Reverse the path (flip horizontal about the centerx point)

Return type:

None

draw(fig, transform, **style)

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

Return type:

None

get_bbox()

Get bounding box (untransformed)

Return type:

BBox

Returns:

Bounding box limits (xmin, ymin, xmax, ymax)

xform(transform, **style)

Return a new Segment that has been transformed to its global position

Parameters:
  • transform – Transformation to apply

  • style – Style parameters from Element to apply as default

Return type:

SegmentPoly

class schemdraw.segments.SegmentText(pos, label, align=None, rotation=None, rotation_mode=None, rotation_global=True, color=None, bgcolor=None, fontsize=14, font=None, mathfont=None, clip=None, zorder=None, visible=True, href=None, decoration=None)

A text drawing segment

Parameters:
  • pos (XY) – (x, y) coordinates for text

  • label (str) – Text to draw

  • align (Optional[tuple[Halign, Valign]]) – Tuple of (horizontal, vertical) alignment where horizontal is (‘center’, ‘left’, ‘right’) and vertical is (‘center’, ‘top’, ‘bottom’)

  • rotation (Optional[float]) – Rotation angle in degrees

  • rotation_mode (Optional[RotationMode]) – See Matplotlib documentation. ‘anchor’ or ‘default’.

  • rotation_global (bool) – Lock rotation to world rather than component. Defaults to True

  • color (Optional[str | tuple[float, float, float]]) – Color for this segment

  • bgcolor (Optional[str | tuple[float, float, float]]) – Background color under the text

  • fontsize (float) – Font size

  • font (Optional[str]) – Font name/family

  • mathfont (Optional[str]) – Math font name/family

  • clip (Optional[BBox]) – Bounding box to clip to

  • zorder (Optional[int]) – Z-order for segment

  • visible (bool) – Show the segment when drawn

doflip()

Vertically flip the element

Return type:

None

doreverse(centerx)

Reverse the path (flip horizontal about the centerx point)

Return type:

None

draw(fig, transform, **style)

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

Return type:

None

get_bbox()

Get bounding box (untransformed)

Return type:

BBox

Returns:

Bounding box limits (xmin, ymin, xmax, ymax)

xform(transform, **style)

Return a new Segment that has been transformed to its global position

Parameters:
  • transform – Transformation to apply

  • style – Style parameters from Element to apply as default

Return type:

SegmentText