Python equivalent of D3.js

前端 未结 15 901
感情败类
感情败类 2021-01-29 17:08

Can anyone recommend a Python library that can do interactive graph visualization?

I specifically want something like d3.js but for python

15条回答
  •  自闭症患者
    2021-01-29 17:54

    One recipe that I have used (described here: Co-Director Network Data Files in GEXF and JSON from OpenCorporates Data via Scraperwiki and networkx ) runs as follows:

    • generate a network representation using networkx
    • export the network as a JSON file
    • import that JSON into to d3.js. (networkx can export both the tree and graph/network representations that d3.js can import).

    The networkx JSON exporter takes the form:

    from networkx.readwrite import json_graph
    import json
    print json.dumps(json_graph.node_link_data(G))
    

    Alternatively you can export the network as a GEXF XML file and then import this representation into the sigma.js Javascript visualisation library.

    from xml.etree.cElementTree import tostring
    writer=gf.GEXFWriter(encoding='utf-8',prettyprint=True,version='1.1draft')
    writer.add_graph(G)
    print tostring(writer.xml)
    

提交回复
热议问题