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: Sequence[XY], color: str | tuple[float, float, float] | None = None, lw: float | None = None, ls: Linestyle | None = None, capstyle: Capstyle | None = None, joinstyle: Joinstyle | None = None, fill: str | None = None, arrow: str | None = None, arrowwidth: float = 0.15, arrowlength: float = 0.25, clip: BBox | None = None, zorder: int | None = None, visible: bool = True)

A segment path

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

  • color – Color for this segment

  • lw – Line width for the segment

  • ls – Line style for the segment ‘-’, ‘–’, ‘:’, etc.

  • 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 – Arrowhead specifier, such as ‘->’, ‘<-’, ‘<->’, ‘-o’, etc.

  • arrowwidth – Width of arrowhead

  • arrowlength – Length of arrowhead

  • clip – Bounding box to clip to

  • zorder – Z-order for segment

  • visible – Show the segment when drawn

doflip() None

Vertically flip the element

doreverse(centerx: float) None

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

draw(fig, transform, **style) None

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

get_bbox() BBox

Get bounding box (untransformed)

Returns:

(xmin, ymin, xmax, ymax)

Return type:

Bounding box limits

xform(transform, **style) Segment

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

class schemdraw.segments.SegmentArc(center: XY, width: float, height: float, theta1: float = 35, theta2: float = -35, arrow: Arcdirection | None = None, angle: float = 0, color: str | tuple[float, float, float] | None = None, lw: float | None = None, ls: Linestyle | None = None, fill: str | None = None, clip: BBox | None = None, zorder: int | None = None, visible: bool = True)

An elliptical arc drawing segment

Parameters:
  • center – Center of the arc ellipse

  • width – Width of the arc ellipse

  • height – Height of the arc ellipse

  • theta1 – Starting angle in degrees

  • theta2 – Ending angle in degrees

  • arrow – Direction of arrowhead (‘cw’ or ‘ccw’)

  • angle – Rotation of the ellipse defining the arc

  • color – Color for this segment

  • lw – Line width for the segment

  • ls – Line style for the segment

  • clip – Bounding box to clip to

  • zorder – Z-order for segment

  • visible – Show the segment when drawn

doflip() None

Vertically flip the element

doreverse(centerx: float) None

Reverse the path (flip horizontal about the centerx point)

draw(fig, transform, **style) None

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

get_bbox() BBox

Get bounding box (untransformed)

Returns:

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

xform(transform, **style) SegmentArc

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

class schemdraw.segments.SegmentBezier(p: Sequence[XY], color: str | tuple[float, float, float] | None = None, lw: float | None = None, ls: Linestyle | None = None, capstyle: Capstyle | None = None, arrow: str | None = None, arrowlength: float = 0.25, arrowwidth: float = 0.15, clip: BBox | None = None, zorder: int | None = None, visible: bool = True)

Quadratic or Cubic Bezier curve segment

Parameters:
  • p – control points (3 or 4)

  • color – Color for this segment

  • lw – Line width for the segment

  • ls – Line style for the segment ‘-’, ‘–’, ‘:’, etc.

  • 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 – Arrowhead specifier, such as ‘->’, ‘<-’, or ‘<->’

  • arrowwidth – Width of arrowhead

  • arrowlength – Length of arrowhead

  • clip – Bounding box to clip to

  • zorder – Z-order for segment

  • visible – Show the segment when drawn

doflip() None

Vertically flip the element

doreverse(centerx: float) None

Reverse the path (flip horizontal about the centerx point)

draw(fig, transform, **style) None

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

get_bbox() BBox

Get bounding box (untransformed)

Returns:

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

xform(transform, **style) SegmentBezier

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

class schemdraw.segments.SegmentCircle(center: XY, radius: float, color: str | tuple[float, float, float] | None = None, lw: float | None = None, ls: Linestyle | None = None, fill: bool | str | None = None, clip: BBox | None = None, zorder: int | None = None, ref: EndRef | None = None, visible: bool = True)

A circle drawing segment

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

  • radius – Radius of the circle

  • color – Color for this segment

  • lw – Line width for the segment

  • ls – Line style for the segment

  • fill – Color to fill if path is closed. True -> fill with element color.

  • clip – Bounding box to clip to

  • zorder – Z-order for segment

  • ref – Flip reference [‘start’, ‘end’, None].

  • visible – Show the segment when drawn

doflip() None

Flip the segment up/down

doreverse(centerx: float) None

Reverse the path (flip horizontal about the centerx point)

draw(fig, transform, **style) None

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

get_bbox() BBox

Get bounding box (untransformed)

Returns:

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

xform(transform, **style) SegmentCircle' | 'SegmentArc

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

class schemdraw.segments.SegmentImage(image: str | BinaryIO, xy: Point = Point(0, 0), width: float = 3, height: float = 1, imgfmt: str | None = None, zorder: int | None = None)

PNG or SVG Image

doflip() None

Vertically flip the element

doreverse(centerx: float) None

Reverse the image

draw(fig, transform, **style) None

Draw the image

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

get_bbox() BBox

Get bounding box (untransformed)

Returns:

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

xform(transform, **style) SegmentImage

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

class schemdraw.segments.SegmentPath(path: Sequence[XY | str], color: str | tuple[float, float, float] | None = None, lw: float | None = None, ls: Linestyle | None = None, capstyle: Capstyle | None = None, joinstyle: Joinstyle | None = None, fill: str | None = None, clip: BBox | None = None, zorder: int | None = None, visible: bool = True)

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

doflip() None

Vertically flip the element

doreverse(centerx: float) None

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

draw(fig, transform, **style) None

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

get_bbox() BBox

Get bounding box (untransformed)

Returns:

(xmin, ymin, xmax, ymax)

Return type:

Bounding box limits

class schemdraw.segments.SegmentPoly(verts: Sequence[XY], closed: bool = True, cornerradius: float = 0, color: str | tuple[float, float, float] | None = None, fill: str | None = None, lw: float | None = None, ls: Linestyle | None = None, hatch: bool = False, joinstyle: Joinstyle | None = None, capstyle: Capstyle | None = None, clip: BBox | None = None, zorder: int | None = None, visible: bool = True)

A polygon segment

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

  • closed – Draw a closed polygon (default True)

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

  • color – Color for this segment

  • fill – Color to fill if path is closed

  • lw – Line width for the segment

  • ls – Line style for the segment

  • hatch – Show hatch lines

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

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

  • clip – Bounding box to clip to

  • zorder – Z-order for segment

  • visible – Show the segment when drawn

doflip() None

Vertically flip the element

doreverse(centerx: float) None

Reverse the path (flip horizontal about the centerx point)

draw(fig, transform, **style) None

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

get_bbox() BBox

Get bounding box (untransformed)

Returns:

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

xform(transform, **style) SegmentPoly

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

class schemdraw.segments.SegmentText(pos: XY, label: str, align: tuple[Halign, Valign] | None = None, rotation: float | None = None, rotation_mode: RotationMode | None = None, rotation_global: bool = True, color: str | tuple[float, float, float] | None = None, fontsize: float = 14, font: str | None = None, mathfont: str | None = None, clip: BBox | None = None, zorder: int | None = None, visible: bool = True)

A text drawing segment

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

  • label – Text to draw

  • align – Tuple of (horizontal, vertical) alignment where horizontal is (‘center’, ‘left’, ‘right’) and vertical is (‘center’, ‘top’, ‘bottom’)

  • rotation – Rotation angle in degrees

  • rotation_mode – See Matplotlib documentation. ‘anchor’ or ‘default’.

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

  • color – Color for this segment

  • fontsize – Font size

  • font – Font name/family

  • mathfont – Math font name/family

  • clip – Bounding box to clip to

  • zorder – Z-order for segment

  • visible – Show the segment when drawn

doflip() None

Vertically flip the element

doreverse(centerx: float) None

Reverse the path (flip horizontal about the centerx point)

draw(fig, transform, **style) None

Draw the segment

Parameters:
  • fig – schemdraw.Figure to draw on

  • transform – Transform to apply before drawing

  • style – Default style parameters

get_bbox() BBox

Get bounding box (untransformed)

Returns:

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

xform(transform, **style) SegmentText

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