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[Union[Sequence[float], Point]], color: Optional[str] = None, lw: Optional[float] = None, ls: Optional[Literal['-', ':', '--', '-.']] = None, capstyle: Optional[Literal['butt', 'round', 'square', 'projecting']] = None, joinstyle: Optional[Literal['bevel', 'miter', 'round']] = None, fill: Optional[str] = None, arrow: Optional[str] = None, arrowwidth: float = 0.15, arrowlength: float = 0.25, clip: Optional[BBox] = None, zorder: Optional[int] = 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: Sequence[float], width: float, height: float, theta1: float = 35, theta2: float = -35, arrow: Optional[Literal['cw', 'ccw']] = None, angle: float = 0, color: Optional[str] = None, lw: Optional[float] = None, ls: Optional[Literal['-', ':', '--', '-.']] = None, clip: Optional[BBox] = None, zorder: Optional[int] = 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.SegmentArrow(tail: Sequence[float], head: Sequence[float], headwidth: Optional[float] = None, headlength: Optional[float] = None, color: Optional[str] = None, lw: Optional[float] = None, clip: Optional[BBox] = None, ref: Optional[Literal['start', 'end']] = None, zorder: Optional[int] = None)

Arrow Segment

[DEPRECATED - use Segment with arrow parameter instead]

class schemdraw.segments.SegmentBezier(p: Sequence[Union[Sequence[float], Point]], color: Optional[str] = None, lw: Optional[float] = None, ls: Optional[Literal['-', ':', '--', '-.']] = None, capstyle: Optional[Literal['butt', 'round', 'square', 'projecting']] = None, arrow: Optional[str] = None, arrowlength: float = 0.25, arrowwidth: float = 0.15, clip: Optional[BBox] = None, zorder: Optional[int] = 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: Sequence[float], radius: float, color: str = None, lw: float = None, ls: Linestyle = None, fill: bool | str | None = None, clip: BBox = None, zorder: int = None, ref: EndRef = 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

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.SegmentPoly(verts: Sequence[Sequence[float]], closed: bool = True, cornerradius: float = 0, color: Optional[str] = None, fill: Optional[str] = None, lw: Optional[float] = None, ls: Optional[Literal['-', ':', '--', '-.']] = None, hatch: bool = False, joinstyle: Optional[Literal['bevel', 'miter', 'round']] = None, capstyle: Optional[Literal['butt', 'round', 'square', 'projecting']] = None, clip: Optional[BBox] = None, zorder: Optional[int] = 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: Sequence[float], label: str, align: Optional[Tuple[Optional[Literal['center', 'left', 'right']], Optional[Literal['center', 'top', 'bottom']]]] = None, rotation: Optional[float] = None, rotation_mode: Optional[Literal['anchor', 'default']] = None, color: Optional[str] = None, fontsize: float = 14, font: Optional[str] = None, mathfont: Optional[str] = None, clip: Optional[BBox] = None, zorder: Optional[int] = 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’.

  • 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