Classes API¶
-
class
schemdraw.elements.
Element
(d=None, **kwargs)¶ Parent class for a single circuit element.
- Keyword Arguments
d (string) – Drawing direction [‘down’, ‘up’, ‘left’, ‘right’] or abbreviated [‘d’, ‘u’, ‘l’, ‘r’]
at (float list [x, y]) – Starting coordinate of element, defaults to current drawing position. OR xy can be tuple of (Element, anchorname) to be resolved after the Element has been placed (see Walrus mode in documentation)
xy (float list [x, y]) – Alias for at keyword
theta (float) – Angle (degrees) of element. Overrides the d parameter.
flip (bool) – Flip the element up/down
reverse (bool) – Reverse the element (for example a DIODE)
zoom (float) – Zoom/magnification factor for element. Default = 1.
anchor (string) – Name of the “pin” in the element to place at xy in the Drawing. Typically used for elements with more than two terminals. For example, an OPAMP element has in1, in2, and out anchors.
toplabel, botlabel, lftlabel, rgtlabel (label,) – Add a string to label the element on the given side. Can be a string or list of strings that will be evenly- spaced along the element ([‘-‘, ‘V1’, ‘+’]). Use $ for latex formatting, for example $R_1 = 100 Omega$. See also: add_label method.
lblofst (float) – Offset between label and element
lblsize (float) – Font size of labels, overrides Drawing.fontsize for this element
lblrotate (bool) – Rotate the label text to align with the element, for example vertical text with an element having d=”up”.
lblloc (['top', 'bot', 'lft', 'rgt', 'center']) – Location for drawing the label specified by label parameter.
zorder (int) – Z-order parameter for placing element in front or behind others.
color (string) – Color for the element
ls (string) – Line style for the element ‘-‘, ‘–’, ‘:’, etc.
lw (float) – Line width for the element
fill (string) – Fill color for elements with closed paths or shapes
move_cur (bool) – Move the Drawing cursor to the endpoint of the element
-
add_label
(label, loc='top', ofst=None, align=None, rotation=0, **kwargs)¶ Add a label to the element
- Parameters
label (string or list) – Text to add. If list, list items will be evenly spaced along the element.
loc (['top', 'bot', 'lft', 'rgt']) – Location for text relative to element
ofst (float or list) – Offset between text and element. Defaults to Element.lblofst. Can be list of [x, y] offets.
align (tuple) – Tuple of (horizontal, vertical) alignment where horizontal is [‘center’, ‘left’, ‘right’] and vertical is [‘center’, ‘top’, ‘bottom’]
rotation (float) – Rotation angle (degrees)
- Keyword Arguments
fontsize (float) – Font size
font –
color (string) – Label text color
-
get_bbox
(transform=False)¶ Get element bounding box, including path and shapes.
- Parameters
transform (bool) – Apply the element transform to the bbox
- Returns
Corners of the bounding box
- Return type
xmin, ymin, xmax, ymax
-
class
schemdraw.elements.
Element2Term
(d=None, **kwargs)¶ - Two terminal element, with automatic lead extensions to result in the
desired length. Anchors: start, center, end.
- to[x, y] float array
The end coordinate of the element
- toxfloat
x-value of end coordinate. y-value will be same as start
- toyfloat
y-value of end coordinate. x-value will be same as start
- lfloat
Total length of element
- endpts: tuple of 2 [x, y] float arrays
The start and end points of the element. Overrides other 2-terminal placement parameters.
Parent class for a single circuit element.
- dstring
Drawing direction [‘down’, ‘up’, ‘left’, ‘right’] or abbreviated [‘d’, ‘u’, ‘l’, ‘r’]
- atfloat list [x, y]
Starting coordinate of element, defaults to current drawing position. OR xy can be tuple of (Element, anchorname) to be resolved after the Element has been placed (see Walrus mode in documentation)
- xyfloat list [x, y]
Alias for at keyword
- thetafloat
Angle (degrees) of element. Overrides the d parameter.
- flipbool
Flip the element up/down
- reversebool
Reverse the element (for example a DIODE)
- zoomfloat
Zoom/magnification factor for element. Default = 1.
- anchorstring
Name of the “pin” in the element to place at xy in the Drawing. Typically used for elements with more than two terminals. For example, an OPAMP element has in1, in2, and out anchors.
- label, toplabel, botlabel, lftlabel, rgtlabelstring or list
Add a string to label the element on the given side. Can be a string or list of strings that will be evenly- spaced along the element ([‘-‘, ‘V1’, ‘+’]). Use $ for latex formatting, for example $R_1 = 100 Omega$. See also: add_label method.
- lblofstfloat
Offset between label and element
- lblsizefloat
Font size of labels, overrides Drawing.fontsize for this element
- lblrotatebool
Rotate the label text to align with the element, for example vertical text with an element having d=”up”.
- lblloc[‘top’, ‘bot’, ‘lft’, ‘rgt’, ‘center’]
Location for drawing the label specified by label parameter.
- zorderint
Z-order parameter for placing element in front or behind others.
- colorstring
Color for the element
- lsstring
Line style for the element ‘-‘, ‘–’, ‘:’, etc.
- lwfloat
Line width for the element
- fillstring
Fill color for elements with closed paths or shapes
- move_curbool
Move the Drawing cursor to the endpoint of the element
-
class
schemdraw.
Drawing
(*elements, unit=3.0, inches_per_unit=0.5, lblofst=0.1, fontsize=16, font='sans-serif', color='black', lw=2, ls='-', fill=None)¶ Create a schematic drawing
- Parameters
*elements (Element) – List of Element instances to add to the drawing
unit (float) – Full length of a 2-terminal element. Inner zig-zag portion of a resistor is 1.0 units.
inches_per_unit (float) – Inches per drawing unit for setting drawing scale
lblofst (float) – Offset between element and its label
fontsize (float) – Default font size for text labels
font (string) – Default font family for text labels
color (string or tuple) – Default color name or RGB (0-1) tuple
lw (float) – Default line width for elements
ls (string) – Default line style ‘-‘, ‘:’, ‘–’, etc.
fill (string or tuple) – Deault fill color for closed elements
-
add
(element, **kwargs)¶ Add an element to the drawing.
- Parameters
element (schemdraw.elements.Element) – The element class to add.
**kwargs (passed to element instantiation if element is a class) –
-
add_elements
(*elements)¶ Add multiple elements to the drawing
-
draw
(showframe=False)¶ Draw the schematic
- Parameters
showframe (bool) – Show axis frame. Useful for debugging a drawing.
-
get_bbox
()¶ Get drawing bounding box
-
get_segments
()¶ Get flattened list of all segments in the drawing
-
labelI
(elm, label='', arrowofst=0.4, arrowlen=2, reverse=False, top=True)¶ Add an arrow element along side another element
- Parameters
elm (Element instance) – Element to add arrow to
label (string or list) – String or list of strings to evenly space along arrow
arrowofst (float) – Distance from element to arrow
arrowlen (float) – Length of arrow as multiple of Drawing.unit
reverse (bool) – Reverse the arrow direction
top (bool) – Draw arrow on top (True) or bottom (False) of element
-
labelI_inline
(elm, label='', botlabel='', d='in', start=True, ofst=0.8)¶ Add an arrowhead for labeling current inline with leads. Works on Element2Term elements.
- Parameters
elm (Element instance) – Element to add arrow to
label (string) – Text to draw above the arrowhead
botlabel (string) – Text to draw below the arrowhead
d (['in', 'out']) – Arrowhead direction, into or out of the element
start (bool) – Place arrowhead near start (True) or end (False) of element
ofst (float) – Offset from center of element
-
loopI
(elm_list, label='', d='cw', theta1=35, theta2=- 35, pad=0.2)¶ Draw an arc to indicate a loop current bordered by elements in list
- Parameters
elm_list (list of Element instances) – Boundary elements in order of top, right, bot, left
label (string) – Text label to draw in center of loop
d (['cw', 'ccw']) – Arc/arrow direction
theta1 (float) – Start angle of arrow arc (degrees)
theta2 (float) – End angle of arrow arc (degrees)
pad (float) – Distance between elements and arc
-
pop
()¶ Pop/load the drawing state. Location and angle are returned to previously pushed state.
-
push
()¶ Push/save the drawing state. Drawing.here and Drawing.theta are saved.
-
save
(fname, transparent=True, dpi=72)¶ Save figure to a file
- Parameters
fname (string) – Filename to save. File type automatically determined from extension (png, svg, jpg)
transparent (bool) – Save as transparent background, if available
dpi (float) – Dots-per-inch for raster formats