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’)
-
fill
(color: bool | str = True) → Element¶ Sets the element fill color.
- Parameters
color – Color string name or hex value, or
to fill with the element line color. (True) –
-
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)
-
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
-
linestyle
(ls: Literal[-, :, --, -.]) → Element¶ Sets the element line style
- Parameters
ls – Line style (‘-‘, ‘:’, ‘–’, ‘-.’).
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)