Skip to content
Snippets Groups Projects
Commit 9dab6caa authored by Steinmann's avatar Steinmann
Browse files

moved multiDi-Graph constructor into .py file

parent f7db18a3
No related branches found
No related tags found
No related merge requests found
import matplotlib.pyplot as plt
import networkx as nx
def construct_graph(*nodes):
#erstelle einen leeren Graphen
graph = nx.MultiDiGraph()
sizeA = 1
for arg in nodes:
if sizeA < len(arg):
sizeA=len(arg)
else:
continue
#erstelle einen Knoten für alle Übergebenen Knoten
for node in nodes:
#für jeden String in den übergebenen Daten wird ein Knoten erstellt
if isinstance(node, str):
graph.add_node(node)
#für jeden übergebenen touple der 2 knoten enthält wird eine Kante erstellt
elif isinstance(node , tuple) and len(node)==2 :
if isinstance(node.__getitem__(0),str) and isinstance(node.__getitem__(1),str):
graph.add_edge(node.__getitem__(0), node.__getitem__(1))
else:
print('Kante enthält unbekannten Knoten')
else:
print('Argument ist weder knoten noch Kante')
continue
pos = nx.spring_layout(graph)
#berechnung der Knotengröße entsprechend der Beschriftungs argumente
nx.draw_networkx_nodes(graph, pos, node_size = sizeA*325, node_color='white', edgecolors='black',linewidths=1)
nx.draw_networkx_edges(graph, pos, edge_color='black',node_size=sizeA*275, arrowsize=20)
nx.draw_networkx_labels(graph, pos)
return graph
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment