如何使用python构建交互式网络 [英] How to build an interactive network using python

查看:245
本文介绍了如何使用python构建交互式网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个互动网络: -

I want to build an interactive network on the lines of :-

http://bl.ocks.org/mbostock/1062288

Class,      Subclass,           Company,    Product,
Chocolate,  Wafer chocolate,    Nestle, KitKat,
Chocolate,  White chocolate,    Nestle, Milkybar,
Chocolate,  White chocolate,    Nestle, Milkybar,
Chocolate,  Caramel chocolate,  Nestle, BarOne,
Chocolate,  Milk chocolate,     Nestle, Nestle Milk chocolate,
Chocolate,  Milk chocolate,     Nestle, Nestle Milk chocolate,
Chocolate,  Milk chocolate,     Nestle, Nestle Milk chocolate,
Chocolate,  Milk chocolate,     Nestle, Nestle Milk chocolate,
Chocolate,  Milk chocolate,     Cadbury,    Dairy milk,

父节点将是Chocolate,其他子级将是: -

The Parent node would be "Chocolate" and further children would be :-

巧克力 - >子类 - >公司 - - >产品。 (每个都应该是click-expand-collapse)

Chocolate--> Subclass-->Company--->Product. (each of these should be click-expand-collapse)

每个节点的大小应该取决于孩子的数量。

The size of each node should depend on number of children.

此外,如果您单击一个节点,它应该展开/折叠以显示其子节点。
有任何方式我可以做到这一点在python。我看着d3,但它的方式太复杂,不明白。是否有更容易的python方式在web浏览器中交互地执行此操作?

Moreover if you click on a node it should expand/collapse to show its children nodes. Is there any way I could do this in python. I looked at d3 but its way too complicated to understand. Is there an easier pythonic way to do this in a web-browser interactively ?

推荐答案

可以使用 d3.js 来做。有一个很好的例子来检查。您还可以使用折叠树,以防您不想使用图表。

You can use d3.js to do that. There is a good example to check. You can also use collapse Tree in case you don't wanna use a graph.

使用教程中的脚本,您的示例应该像 。如果你不想使用collaspe / expand结构。您可以使用d3.js构建图形,它看起来像

Using the script in the tutorial, your example should work like this. If you are not looking to use collaspe/expand structure. You can use d3.js to build a graph, and it would look like this.

    root = {
 "name": "Chocolate", "tag":"class",
 "children": [
  {
   "name": "Wafer", "tag":"subclass",
   "children": [
    {
      "name": "Nestle", "tag":"company",
     "children": [
      {"name": "KitKat", "tag":"product"}
     ]
    }
   ]
  },

  {
   "name": "White", "tag":"subclass",
   "children": [
    {
      "name": "Nestle", "tag":"company",
     "children": [
      {"name": "Milkybar", "tag":"product"}
     ]
    }
   ]
  },

    {
   "name": "Caramel", "tag":"subclass",
   "children": [
    {
      "name": "Nestle", "tag":"company",
     "children": [
      {"name": "BarOne", "tag":"product"}
     ]
    }
   ]
  },    
    {
   "name": "Milk", "tag":"subclass",
   "children": [
    {
      "name": "Nestle", "tag":"company",
     "children": [
      {"name": "Nestle Milk", "tag":"product"}
     ]
    },  {
      "name": "Cadbury", "tag":"company",
     "children": [
      {"name": "Dairy Milk", "tag":"product"}
     ]
    }
   ]
  }




 ]
};

这篇关于如何使用python构建交互式网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆