Python
import matplotlib.pyplot as plt import matplotlib.patches as mpatches # Create a figure and axis for drawing the schematic fig, ax = plt.subplots(figsize=(15, 10)) # Define positions for each component positions = { "BATT1": (1, 9), "PowerNet1": (2, 9), "GND": (4, 2), "SW1": (4, 9), "R1": (6, 9), "D1": (8, 9), "L1": (3, 7), "C1": (5, 7), "R2": (1, 5), "J1": (4, 5), "P1": (6, 6), "P3": (7, 5) } components = { "BATT1": ("Battery", "BATT1:+", "BATT1:-"), "PowerNet1": ("Power Net", "Power"), "GND": ("Ground", "GND:GND"), "SW1": ("Switch", "SW1:P1", "SW1:P2"), "R1": ("Resistor", "R1:P1", "R1:P2"), "D1": ("LED/Dioide", "D1:A", "D1:K"), "L1": ("Inductor", "L1:P1", "L1:P2"), "C1": ("Capacitor", "C1:P1", "C1:P2"), "R2": ("Resistor", "R2:P1", "R2:P2"), "J1": ("Jack", "J1:PIN_1", "J1:PIN_2", "J1:PIN_3", "J1:PIN_4"), "P1": ("Terminal", "P1:1"), "P3": ("Terminal", "P3:1") } # Draw components and connections on the schematic for comp_name, (label, *pins) in components.items(): pos = positions[comp_name] ax.text(pos[0], pos[1], label, ha='center', va='center', bbox=dict(boxstyle="round,pad=0.3", edgecolor='black', facecolor='lightgrey')) if comp_name in ["BATT1", "SW1", "R1", "D1", "L1", "C1", "R2", "J1"]: for pin in pins: ax.annotate(pin, (pos[0], pos[1]), textcoords="offset points", xytext=(-30, 10), ha='center', fontsize=9) # Add connections connections = [ ("BATT1:+", "PowerNet1", 0), ("BATT1:-", "GND:GND", 0), ("PowerNet1", "SW1:P1", 1), ("SW1:P2", "R1:P1", 0), ("R1:P2", "D1:A", 1), ("D1:K", "GND:GND", 0), ("PowerNet1", "L1:P1", 1), ("L1:P2", "C1:P1", 1), ("C1:P2", "GND:GND", 1), ("PowerNet1", "R2:P1", 1), ("GND:GND", "J1:PIN_1", 1), ("C1:P1", "J1:PIN_2", 1), ("R2:P2", "P1:1", 1), ("D1:A", "J1:PIN_4", 0) ] # Draw wires as lines between coordinates for (start_label, end_label, offset) in connections: start_pos = None end_pos = None for comp_name, pos in positions.items(): labels = components[comp_name] if any(start_label.startswith(label) for label in labels): start_pos = pos if any(end_label.startswith(label) for label in labels): end_pos = pos if start_pos and end_pos: ax.plot([start_pos[0]+offset, end_pos[0]+offset], [start_pos[1], end_pos[1]], 'k-') # Configure plot limits and remove axes ax.set_xlim(0, 10) ax.set_ylim(0, 12) ax.axis('off') plt.show()
commentFileId-58f2a43d5b817bc28af46d6126fa9daa9cd5f274417950199d0d6289b3a3cfe2.png
Audio Electronics | Copilot Preset
schone
copilot