Schemdraw
Schemdraw is a Python package for producing high-quality electrical circuit schematic diagrams. It allows users to create diagrams by adding circuit elements one at a time using Python methods. It supports a wide range of components including resistors, capacitors, diodes, transistors, opamps, logic gates, and can also generate timing diagrams, state machine diagrams, and flowcharts. The current version is 0.22 and it has an active development and release cadence.
Warnings
- breaking The `Drawing` class introduced a context manager (`with schemdraw.Drawing():`) in version 0.14. Using the context manager syntax with older versions will result in an `AttributeError: __enter__`.
- gotcha When running schemdraw on headless servers or environments without a GUI display, calling `d.draw()` can lead to failures as it attempts to open an interactive Matplotlib window.
- breaking As of version 0.18, subclasses of `ElementCompound` must define their `Segments` within a `setup` method instead of the `__init__` method.
- gotcha The `schemdraw.logic.logicparse` function returns a `Drawing` object itself and should *not* be placed inside a `with schemdraw.Drawing():` context manager. Doing so can result in blank output or unexpected behavior.
Install
-
pip install schemdraw -
pip install schemdraw[matplotlib] -
pip install schemdraw[svgmath]
Imports
- schemdraw
import schemdraw
- schemdraw.elements
import schemdraw.elements as elm
- SchemDraw
import schemdraw
Quickstart
import schemdraw
import schemdraw.elements as elm
with schemdraw.Drawing(file='basic_rc_circuit.svg') as d:
d += elm.Resistor().right().label('1Ω')
d += elm.Capacitor().down().label('10μF')
d += elm.Line().left()
d += elm.SourceSin().up().label('10V')
# The drawing is automatically saved to 'basic_rc_circuit.svg' upon exiting the 'with' block.