Currently trying to display the edge weights from a network x graph in Manim, here is my current code:
from manim import *
import networkx as nx
class Run(Scene):
def construct(self):
G = nx.Graph()
G.add_nodes_from([node for node in "abcdef"])
G.add_edge("a","b", weight=17)
G.add_edge("a","c", weight=12)
G.add_edge("a","d", weight=8)
G.add_edge("b","c", weight=1)
G.add_edge("b","e", weight=6)
G.add_edge("c","d", weight=7)
G.add_edge("c","f", weight=11)
G.add_edge("d","f", weight=15)
G.add_edge("e","f", weight=5)
edge_labels = nx.get_edge_attributes(G, "weight")
pos = nx.spring_layout(G)
nx.draw_networkx_edges(G, pos)
nx.draw_networkx_nodes(G, pos)
nx.draw_networkx_labels(G,pos)
nx.draw_networkx_edge_labels(G, pos, edge_labels)
self.play(Create(Graph(list(G.nodes), list(G.edges), layout="spring", layout_scale=3, root_vertex="None", edge_config={("a","b"): {"stroke_color": RED}}))))
self.wait()
A huge part of animating this algorithm will be showing the weighted edge values. As you can see, I've coded them into my graph but they do not appear when the graph is made in the video. Maybe I overlooked something in the documentation, but does anyone have any suggestions on how to display edge weights in an NX graph in Manim?