Schemadraw is a python library that converts a high-level
placement file of components directly into a detailed
circuit drawing in SVG. The key benefit for using
schemadraw is that the actual placement of components
in a schematic does not have to be specified in the schemadraw
file. Only relative positioning (left, right, up down) needs
to be specified. This is an ideal match with LLMs since
LLMs are good at understanding relative positioning, but
they are not good at absolute placement of components, wires or labels in a circuit diagram.
fromschemdrawimportDrawingimportschemdraw.elementsaselmimportmatplotlib.pyplotaspltwithDrawing(file='led-circuit-battery.svg')asd:# Vertical battery on the left with "+" on topvsrc=d.add(elm.Battery().up().reverse().label('+5V',loc='top'))# Top branch - just a wire at the topd+=elm.Line().right()# Right side of the circuit vertical resistor to LEDd+=elm.Resistor().down().label('150 Ω')d+=elm.LED().down().label('Red LED')# Horizontal line back toward the batteryd+=elm.Line().left().length(3)# Draw ground heregnd=d.add(elm.Ground())# Connect ground up to the negative battery terminal with a separate line# Draw a vertical line up from the ground to the negative terminal# Do not draw over the batteryd+=elm.Line().up().length(3)# Save PNG with white backgroundfig=d.draw(show=False)plt.savefig('led-circuit-battery.png',dpi=300,bbox_inches='tight',facecolor='white')
Note the battery has the reverse() method for positive polarity on the top.