make graph visualizer better

This commit is contained in:
2026-03-04 10:23:05 +11:00
parent 3667bb5477
commit 14517a4ba3

View File

@@ -10,13 +10,17 @@ def random_colour():
return f"rgb({randint(0,255)},{randint(0,255)},{randint(0,255)})" return f"rgb({randint(0,255)},{randint(0,255)},{randint(0,255)})"
def main(): def main():
net = Network(notebook=False, cdn_resources="remote", neighborhood_highlight=True, bgcolor="#222222", font_color="#FAFAFA") net = Network(notebook=False, cdn_resources="remote", neighborhood_highlight=True, bgcolor="#222222", font_color="#FAFAFA", layout="hierarchical")
net.repulsion(spring_length=300)
net.add_nodes([1,2,3,4,5,6,7,8,9,10], label=["1","2","3","4","5","6","7","8","9","10"],color=[random_colour() for _ in range(10)]) net.add_nodes([0,1,2,3,4], label=['1','2','3','4','5'])
net.add_edges([(1, 2, 10), (1, 3, 5), (1, 4, 6), (2, 3, 10), (2, 5, 1), (5, 6, 9), (7, 8, 7), (8, 9, 7), (9, 7, 8), (1, 7, 7), (9, 10, 2)]) net.add_edge(0, 1, length=500)
net.add_edge(0, 2, length=500)
net.add_edge(0, 3, length=500)
net.add_edge(2, 3, length=250)
net.add_edge(3, 4, length=500)
net.show("network.html", notebook=False)
net.write_html("network.html", notebook=False)
if __name__ == "__main__": if __name__ == "__main__":