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.