Drawing

class schemdraw.Drawing(*elements: schemdraw.elements.elements.Element, unit: Optional[float] = None, inches_per_unit: Optional[float] = None, lblofst: Optional[float] = None, fontsize: Optional[float] = None, font: Optional[str] = None, color: Optional[str] = None, lw: Optional[float] = None, ls: Optional[Literal['-', ':', '--', '-.']] = None, fill: Optional[str] = None)

A schematic drawing

See schemdraw.config method for argument defaults

Parameters
  • *elements – List of Element instances to add to the drawing

  • unit – Full length of a 2-terminal element. Inner zig-zag portion of a resistor is 1.0 units.

  • inches_per_unit – Inches per drawing unit for setting drawing scale

  • lblofst – Default offset between element and its label

  • fontsize – Default font size for text labels

  • font – Default font family for text labels

  • color – Default color name or RGB (0-1) tuple

  • lw – Default line width for elements

  • ls – Default line style

  • fill – Deault fill color for closed elements

here

(xy tuple) Current drawing position. The next element will be added at this position unless specified otherwise.

theta

(float) Current drawing angle, in degrees. The next element will be added with this angle unless specified otherwise.

add(element: Element | Type[Element], **kwargs) Element

Add an element to the drawing.

Parameters

element – The element to add.

add_elements(*elements: schemdraw.elements.elements.Element) None

Add multiple elements to the drawing

draw(showframe: bool = False, show: bool = True, ax=None, backend: Optional[Literal['svg', 'matplotlib']] = None)

Draw the schematic

Parameters
  • showframe – Show axis frame. Useful for debugging a drawing.

  • show – Show the schematic in a GUI popup window (when outside of a Jupyter inline environment)

  • ax – Existing axis to draw on. Should be set to equal aspect for best results.

Returns

schemdraw Figure object

get_bbox() schemdraw.types.BBox

Get drawing bounding box

get_imagedata(fmt: ImageFormat | ImageType) bytes

Get image data as bytes array

Parameters

fmt – Format or file extension of the image type

Returns

Image data as bytes

get_segments() list['Segment' | 'SegmentText' | 'SegmentArc' | 'SegmentArrow' | 'SegmentCircle' | 'SegmentPoly']

Get flattened list of all segments in the drawing

interactive(interactive: bool = True)

Enable interactive mode (matplotlib backend only). Matplotlib must also be set to interactive with plt.ion().

move(dx: float, dy: float) None

Move the current drawing position

Parameters
  • dx – change in x position

  • dy – change in y position

pop() None

Pop/load the drawing state. Location and angle are returned to previously pushed state.

push() None

Push/save the drawing state. Drawing.here and Drawing.theta are saved.

save(fname: str, transparent: bool = True, dpi: float = 72) None

Save figure to a file

Parameters
  • fname – Filename to save. File type automatically determined from extension (png, svg, jpg)

  • transparent – Save as transparent background, if available

  • dpi – Dots-per-inch for raster formats

undo() None

Removes previously added element

Element

class schemdraw.elements.Element(*d, **kwargs)

Standard circuit element.

Keyword Arguments are equivalent to calling setter methods.

Parameters

d – Drawing direction (‘up’, ‘down’, ‘left’, ‘right’)

anchors

Dictionary of anchor positions in element coordinates

absanchors

Dictionary of anchor positions in absolute drawing coordinates

segments

List of drawing primitives making up the element

transform

Transformation from element to drawing coordinates

Anchor names are dynmically added as attributes after placing the element in a Drawing.

anchor(anchor: str) Element

Specify anchor for placement. The anchor will be aligned with the position specified by at() method.

at(xy: XY | tuple['Element', str]) Element

Set the element xy position

Parameters

xy – (x,y) position or tuple of (Element, anchorname)

color(color: str) Element

Sets the element color

Parameters

color – color name or hex value (ie ‘#FFFFFF’)

down() Element

Set the direction to down

fill(color: bool | str = True) Element

Sets the element fill color.

Parameters
  • color – Color string name or hex value, or

  • color. (True to fill with the element line) –

flip() Element

Apply flip up/down

get_bbox(transform=False, includetext=True)

Get element bounding box

Parameters
  • transform – Apply the element transform to the bbox to get bounds in Drawing coordinates

  • includetext – Consider text when calculating bounding box. Text width and height can vary by font, so this produces an estimate of bounds.

Returns

Corners of the bounding box, (xmin, ymin, xmax, ymax)

hold() Element

Do not move the Drawing here position after placing this element

label(label: str | Sequence[str], loc: LabelLoc = None, ofst: XY | float | None = None, halign: Halign = None, valign: Valign = None, rotate: bool | float = False, fontsize: float = None, font: str = None, color: str = None)

Add a label to the Element.

Parameters
  • label – The text string or list of strings. If list, each string will be evenly spaced along the element (e.g. [‘-’, ‘V’, ‘+’])

  • loc – Label position within the Element. Either (‘top’, ‘bottom’, ‘left’, ‘right’), or the name of an anchor within the Element.

  • ofst – Offset from default label position

  • halign – Horizontal text alignment (‘center’, ‘left’, ‘right’)

  • valign – Vertical text alignment (‘center’, ‘top’, ‘bottom’)

  • rotate – True to rotate label with element, or specify rotation angle in degrees

  • fontsize – Size of label font

  • font – Name/font-family of label

  • color – Color of label

left() Element

Set the direction to left

linestyle(ls: Literal['-', ':', '--', '-.']) Element

Sets the element line style

Parameters

ls – Line style (‘-’, ‘:’, ‘–’, ‘-.’).

linewidth(lw: float) Element

Sets the element line width

Parameters

lw – Line width

reverse() Element

Apply reverse left/right

right() Element

Set the direction to right

scale(scale: float = 1) Element

Apply scale/zoom factor to element

style(color: Optional[str] = None, fill: Optional[str] = None, ls: Optional[Literal['-', ':', '--', '-.']] = None, lw: Optional[float] = None) Element

Apply all style parameters

Parameters
  • color – Color string or hex value

  • fill – Color string or hex

  • ls – Line style (‘-’, ‘:’, ‘–’, ‘-.’)

  • lw – Line width

theta(theta: float) Element

Set the drawing direction angle in degrees

up() Element

Set the direction to up

zorder(zorder: int) Element

Sets the element zorder. Higher zorders will be drawn above lower zorder elements.

Element2Term

class schemdraw.elements.Element2Term(*d, **kwargs)

Two terminal element. The element leads can be automatically extended to the start and ending positions.

Anchors:
  • start

  • center

  • end

endpoints(start: Union[Sequence[float], schemdraw.util.Point], end: Union[Sequence[float], schemdraw.util.Point]) Element2Term

Sets absolute endpoints of element

length(length: float) Element2Term

Sets total length of element

to(xy: Union[Sequence[float], schemdraw.util.Point]) Element2Term

Sets ending position of element

tox(x: float | XY | Element) Element2Term

Sets ending x-position of element (for horizontal elements)

toy(y: float | XY | Element) Element2Term

Sets ending y-position of element (for vertical elements)

ElementDrawing

class schemdraw.elements.ElementDrawing(drawing, **kwargs)

Create an element from a Drawing

Parameters

drawing – The Drawing instance to convert to an element

Element Style

schemdraw.elements.style(style)

Set global element style

Parameters

style – dictionary of {elementname: Element} to change the element module namespace. Use elements.STYLE_US or elements.STYLE_IEC to define U.S. or European/IEC element styles.