Drawing schematics in python

An example of drawing a simple circuit using schemdraw v0.6.0

This example uses schemdraw==0.6.0, but the code breaks with newer versions. TODO: update for newer schemdraw versions

import SchemDraw as sd
import SchemDraw.elements as elm

d = sd.Drawing()
V1 = d.add(elm.SOURCE_V, label='$V_g$')
d.add(elm.LINE, d='right', l=0.1*d.unit)
L1 = d.add(elm.INDUCTOR2, d='right', label='L', l=d.unit*0.75)
d.labelI_inline(L1, '$i_L$')

d.add(elm.RES, d='right', label='$R_L$', l=d.unit*0.75)
S1 = d.add(elm.SWITCH_SPDT2, d='right', anchor='a', toplabel='2', botlabel='1')

J1 = d.add(elm.LINE, d='right', xy=S1.b,  l=d.unit*.5)
J2 = d.add(elm.LINE, d='right', l=d.unit*.5)

d.add(elm.LINE, d='right', l=0.5*d.unit)
d.add(elm.GAP, d='down', toy=V1.start, label=['+', '$v$', '$-$'])

d.add(elm.LINE, d='down',toy=V1.start)
d.add(elm.LINE, to=V1.start)

d.add(elm.LINE, xy=S1.c, d='down', toy=V1.start)
C1 = d.add(elm.CAP, xy=J1.end, d='down', toy=V1.start, label='C')
d.add(elm.RES, xy=J2.end, d='down', toy=V1.start, label='R')
d.labelI_inline(C1, '$i_C$')

drawing schematics in python

Canonical form for an ideal single-inductor, single-capactir, CCM converter

import SchemDraw as sd
import SchemDraw.elements as elm

d = sd.Drawing()

Vg = d.add(elm.SOURCE_V, label=r'$V_g + \hat{v}_g(s)$')
n1 = d.add(elm.LINE, d='right', l=1.2*d.unit)
j = d.add(elm.SOURCE_I, d='down', label=r'$j(s)\hat{d}(s)$')
e = d.add(elm.SOURCE_V, d='right', xy=n1.end, label=r'$e(s)\hat{d}(s)$')
d.add(elm.LINE, d='right', l=0.3*d.unit)

X1 = d.add(elm.transformer(t1=6, t2=6, loop=True, core=False), label="1 : M(D)", anchor='p1')

Le = d.add(elm.INDUCTOR2, label='$L_e$')
J1 = d.add(elm.LINE, d='right', l=d.unit*.75)
J2 = d.add(elm.LINE, d='right', l=d.unit*.75)

d.add(elm.GAP, d='down', xy=J1.end, label=['+', '', '', r'$V + \hat{v}(s)$', '', '', '$-$'])
R1 = d.add(elm.RES, xy=J2.end, d='down', toy=Vg.start, label='R')
d.add(elm.LINE, d='left', tox=X1.s2)
d.add(elm.LINE, d='up', toy=X1.s2)
d.add(elm.LINE, xy=X1.p2, d='down', toy=Vg.start)
d.add(elm.LINE, d='left', tox=Vg.start)

C = d.add(elm.CAP, xy=Le.end, d='down', label='C')

drawing schematics in python

Total running time of the script: ( 0 minutes 0.777 seconds)

Gallery generated by Sphinx-Gallery