从包含图的.dot文件创建图

我有一个.dot文件,并希望将有向图的内容显示为可视图 当我运行它不断得到一个错误。我看过很多文章,但没有找到可以使用的解决方案。

import graphviz as pgv
import networkx as nx
import matplotlib as plt

def load_json(filename):
    import json
    with open(filename,'r') as file:
        content = "\n".join(file.readlines())
        return json.loads(content)


distance_graph = load_json('../Main/distancetables.json')

with open('../Main/distancetable.dot','wt') as file:
    print('Writing: ../Main/distancetable.dot')
    file.write('digraph {\n')
    for city in distance_graph.keys():
        for adjacent_city in distance_graph[city].keys():
            distance = distance_graph[city][adjacent_city]
            file.write('\t"{}" -> "{}"[label="{}",weight="{}"];\n'.format(city,adjacent_city,distance,distance))
    file.write("}\n")

Gtemp = pgv.Digraph('../Main/distancetable.dot')
G = nx.Graph(Gtemp)
nx.draw(G)
plt.show()

错误:to_networkx_graph中的第165行     “输入不是要转换的已知数据类型。”) networkx.exception.NetworkXError:输入不是要转换的已知数据类型。

chejixian 回答:从包含图的.dot文件创建图

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3149676.html

大家都在问