fork download
  1. import matplotlib.pyplot as plt
  2. import networkx as nx
  3.  
  4. # สร้างกราฟแทนวงจร
  5. G = nx.Graph()
  6.  
  7. # ตำแหน่งของจุดต่าง ๆ
  8. positions = {
  9. 'A': (0, 0),
  10. 'M': (1, 1.5),
  11. 'C': (2, 3),
  12. 'D': (2, 0),
  13. 'E': (3, 1.5),
  14. 'B': (4, 0)
  15. }
  16.  
  17. # เพิ่มตัวต้านทาน (หน่วย: โอห์ม)
  18. edges = [
  19. ('A', 'M', 1.905),
  20. ('M', 'C', 1.905),
  21. ('M', 'D', 3.048),
  22. ('C', 'E', 8),
  23. ('D', 'E', 6),
  24. ('E', 'B', 8),
  25. ('A', 'B', 7)
  26. ]
  27.  
  28. # เพิ่มเส้นเชื่อมและค่าความต้านทานลงในกราฟ
  29. for u, v, r in edges:
  30. G.add_edge(u, v, resistance=r)
  31.  
  32. # วาดวงจร
  33. plt.figure(figsize=(10, 6))
  34. nx.draw(G, pos=positions, with_labels=True, node_color='lightblue', node_size=1200, font_size=14, font_weight='bold')
  35. edge_labels = {(u, v): f"{d['resistance']}Ω" for u, v, d in G.edges(data=True)}
  36. nx.draw_networkx_edge_labels(G, pos=positions, edge_labels=edge_labels, font_size=12)
  37.  
  38. plt.title("วงจรที่แปลงรูปสามเหลี่ยม A-C-D เป็นรูปดาว (Delta to Star)", fontsize=14)
  39. plt.axis('off')
  40. plt.tight_layout()
  41. plt.show()
  42.  
Success #stdin #stdout 0.03s 25636KB
stdin
Standard input is empty
stdout
import matplotlib.pyplot as plt
import networkx as nx

# สร้างกราฟแทนวงจร
G = nx.Graph()

# ตำแหน่งของจุดต่าง ๆ
positions = {
    'A': (0, 0),
    'M': (1, 1.5),
    'C': (2, 3),
    'D': (2, 0),
    'E': (3, 1.5),
    'B': (4, 0)
}

# เพิ่มตัวต้านทาน (หน่วย: โอห์ม)
edges = [
    ('A', 'M', 1.905),
    ('M', 'C', 1.905),
    ('M', 'D', 3.048),
    ('C', 'E', 8),
    ('D', 'E', 6),
    ('E', 'B', 8),
    ('A', 'B', 7)
]

# เพิ่มเส้นเชื่อมและค่าความต้านทานลงในกราฟ
for u, v, r in edges:
    G.add_edge(u, v, resistance=r)

# วาดวงจร
plt.figure(figsize=(10, 6))
nx.draw(G, pos=positions, with_labels=True, node_color='lightblue', node_size=1200, font_size=14, font_weight='bold')
edge_labels = {(u, v): f"{d['resistance']}Ω" for u, v, d in G.edges(data=True)}
nx.draw_networkx_edge_labels(G, pos=positions, edge_labels=edge_labels, font_size=12)

plt.title("วงจรที่แปลงรูปสามเหลี่ยม A-C-D เป็นรูปดาว (Delta to Star)", fontsize=14)
plt.axis('off')
plt.tight_layout()
plt.show()