简体   繁体   English

Manim NetworkX Graph 中的加权边

[英]Weighted Edges in Manim NetworkX Graph

Currently trying to display the edge weights from a.network x graph in Manim, here is my current code:目前正在尝试在 Manim 中显示 a.network x 图中的边权重,这是我当前的代码:

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()

Here is the current output:这是当前的 output: 没有加权边的 NX 图

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?也许我忽略了文档中的某些内容,但是有人对如何在 Manim 的 NX 图中显示边权重有任何建议吗?

There isn't a built-in way of doing this in Manim, but would be a good enhancement request. Manim 中没有执行此操作的内置方法,但会是一个很好的增强请求。 I checked on GitHub and didn't see any issue open for this enhancement yet.我检查了 GitHub 并没有发现任何针对此增强功能的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM