Python equivalent of D3.js

前端 未结 15 726
感情败类
感情败类 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:45

    You can also choose to serialize your data and then visualize it in D3.js, as done here: Use Python & Pandas to Create a D3 Force Directed Network Diagram (It comes with a jupyter notebook as well!)

    Here is the gist. You serialize your graph data in this format:

    import json
    json_data = {
      "nodes":[
        {"name":"Myriel","group":1},
        {"name":"Napoleon","group":1},
        {"name":"Mlle.Baptistine","group":1},
        {"name":"Mme.Magloire","group":1},
        {"name":"CountessdeLo","group":1},
      ],
      "links":[
        {"source":1,"target":0,"value":1},
        {"source":2,"target":0,"value":8},
        {"source":3,"target":0,"value":10},
        {"source":3,"target":2,"value":6},
        {"source":4,"target":0,"value":1},
        {"source":5,"target":0,"value":1},
      ]
    }
    filename_out = 'graph_data.json'
    json_out = open(filename_out,'w')
    json_out.write(json_data)
    json_out.close()
    

    Then you load the data in with d3.js:

    d3.json("pcap_export.json", drawGraph);
    

    For the routine drawGraph I refer you to the link, however.

提交回复
热议问题