Example #1
0
def drawGraph(nodes, links, name):
    # 图表初始化配置
    init_opts = opts.InitOpts(page_title=name, height="700px")
    g = Graph(init_opts=init_opts)
    # 标题配置
    title = opts.TitleOpts(title=name, pos_left='center')
    # 图例配置
    legend_opts = opts.LegendOpts(pos_top="5%", pos_left="15%")
    # 工具箱配置
    # 工具箱配置
    toolbox_opts = opts.ToolboxOpts()
    g.set_global_opts(
        title_opts=title,
        legend_opts=legend_opts,
        toolbox_opts=toolbox_opts,
    )

    g.add(
        "",
        nodes,
        links,
        repulsion=8000,
        linestyle_opts=opts.LineStyleOpts(curve=0.2),
    )
    g.render("{0}.html".format(name))
 def draw(self):
     nodes_data = []
     sort_people = sorted(self.people.items(),
                          key=lambda item: item[1],
                          reverse=True)
     for key, value in sort_people:
         nodes_data.append(opts.GraphNode(name=key,
                                          symbol_size=value / 80))  # 节点出现次数
     links_data = []
     for key, key_value in self.relationship.items():
         for key2, value in key_value.items():
             links_data.append(
                 opts.GraphLink(source=key, target=key2,
                                value=value))  # 节点之间权值
     c = Graph(init_opts=opts.InitOpts(width="1200px",
                                       height="800px"))  # 调用类
     c.add(
         "",
         nodes_data,  # 关系图节点数据项列表
         links_data,  # 关系图节点间关系数据项列表
         layout="circular",
         repulsion=800,  # 节点之间的斥力因子
         edge_length=100,  # 边的两个节点之间的距离
         linestyle_opts=opts.LineStyleOpts(curve=0.3),  # 关系边的公用线条样式
         label_opts=opts.LabelOpts(position="right"),
     )
     c.set_global_opts(title_opts=opts.TitleOpts(title="人物图谱"))
     c.render("人物图谱.html")
Example #3
0
def DrawWithPye(links, nodes, name):
    graph = Graph(opts.InitOpts(width=g.w_s, height=g.h_s))
    graph.add("Node Name: ",
              nodes,
              links,
              repulsion=g.repul,
              label_opts=opts.LabelOpts(is_show=g.label),
              is_draggable=g.drag)
    graph.set_global_opts(title_opts=opts.TitleOpts(title=name + g.titleend))
    graph.render()
Example #4
0
def draw_graph():
    nodes_for_draw = []
    links_for_draw = []
    for node in default_graph.nodes:
        nodes_for_draw.append({'name': node.name, "symbolSize": 50})
    for node in default_graph.nodes:
        for child in node.children:
            links_for_draw.append({'source': node.name, 'target': child.name})
    graph = Graph(init_opts=opts.InitOpts(width='1800px', height='1000px'))
    graph.set_global_opts(
        title_opts=opts.TitleOpts(title="MatrixSlow Graph"))
    graph.add("", nodes_for_draw, links_for_draw, layout='force',
              repulsion=8000, edge_symbol=['circle', 'arrow'])

    graph.render('./aaa.html')
Example #5
0
class DrawGraph(object):
    def __init__(self, width="1200px", height="800px"):
        self.graph = Graph(
            init_opts=opts.InitOpts(
                width=width,
                height=height,
                bg_color='rgba(255,255,255)'
            )
        ).set_global_opts(
            # 设置显示工具栏
            toolbox_opts=opts.ToolboxOpts(
                feature=opts.ToolBoxFeatureOpts(
                    save_as_image=opts.ToolBoxFeatureSaveAsImageOpts(
                        name='networks',  # 设置工具栏图片保存的文件名
                    ),
                )
            )
        )
        self.line_width = 1

    def setting(self, title=None, line_width: int = None):
        if title:
            self.graph.set_global_opts(title_opts=opts.TitleOpts(title=title), )
        if line_width:
            self.line_width = line_width
        return self

    def exec_draw(self, nodes, links):
        self.graph.add('',
                       nodes,
                       links,
                       repulsion=1000,
                       is_draggable=True,  # 节点是否可拖拽,只在使用力引导布局的时候有用。
                       layout='force',
                       linestyle_opts=opts.LineStyleOpts(width=self.line_width),
                       )
        return self

    def render(self, path):
        return self.graph.render(path)

    def save_img(self, fp=None, page=None):
        if fp is None:
            fp = 'result.png'

        if page is None:
            fp = 'render.html'
        make_snapshot(snapshot, self.graph.render(page), fp)
Example #6
0
def Graph_with_edge_options(nodes_data, links_data):
    Graph_tuopu = Graph()
    ## 配置大小
    Graph_tuopu.__init__(
        init_opts=opts.InitOpts(width="1100px", height="1500px"))
    Graph_tuopu.add(
        "",
        nodes_data,
        links_data,
        repulsion=4000,
        # edge_label=opts.LabelOpts(
        #     is_show=True, position="middle", formatter="{b} 的数据 {c}"
        # ),
        itemstyle_opts=opts.ItemStyleOpts(color="gray"))
    Graph_tuopu.set_global_opts(title_opts=opts.TitleOpts(
        title="topology_edges_node.json"))
    Graph_tuopu.render("graph_with_edge_options.html")
    webbrowser.open("../../Game/suning2020/graph_with_edge_options.html")
    print("OK")
Example #7
0
    node_in_graph.append(opts.GraphNode(
            name=one_line_list[0], 
            value=int(one_line_list[1]), 
            symbol_size=int(one_line_list[1])/20,  # 手动调整节点的尺寸
            category=int(one_line_list[2])))  # 类别,例如categories[2]=='蜀'
#print('-'*20)  # 测试点
link_in_graph = []
for one_line in link_line_list:
    one_line = one_line.strip('\n')
    one_line_list = one_line.split(',')
    #print(one_line_list)  # 测试点
    link_in_graph.append(opts.GraphLink(
            source=one_line_list[0], 
            target=one_line_list[1], 
            value=int(one_line_list[2])))


##--- 第3步:画图
c = Graph(init_opts=opts.InitOpts(page_title='关系图-仿生人会梦见电子羊吗?',width='1400px',height='700px'))
c.add("", 
      node_in_graph, 
      link_in_graph, 
      edge_length=[10,400], 
      repulsion=100,
      categories=categories, 
      is_draggable = True,
#      linestyle_opts=opts.LineStyleOpts(curve=0.2),  # 增加连线弧度
      layout="force",  # "force"-力引导布局,"circular"-环形布局
      )
c.set_global_opts(title_opts=opts.TitleOpts(title="关系图-仿生人会梦见电子羊吗?"))
c.render(out_file_name)
Example #8
0
    one_line = one_line.strip('\n')
    one_line_list = one_line.split(',')
    #print(one_line_list)  # 测试点
    node_in_graph.append(
        opts.GraphNode(name=one_line_list[0],
                       value=int(one_line_list[1]),
                       symbol_size=int(one_line_list[1]) / 20))  # 手动调整节点的尺寸
#print('-'*20)  # 测试点
link_in_graph = []
for one_line in link_line_list:
    one_line = one_line.strip('\n')
    one_line_list = one_line.split(',')
    print(one_line_list)  # 测试点
    link_in_graph.append(
        opts.GraphLink(source=one_line_list[0],
                       target=one_line_list[1],
                       value=int(one_line_list[2])))

##--- 画图
c = Graph()
c.add(
    "",
    node_in_graph,
    link_in_graph,
    edge_length=[10, 50],
    repulsion=5000,
    layout="force",  # "force"-力引导布局,"circular"-环形布局
)
c.set_global_opts(title_opts=opts.TitleOpts(title="关系图-红楼梦人物"))
c.render(out_file_name)
Example #9
0
    one_line = one_line.strip('\n')
    one_line_list = one_line.split(',')
    #print(one_line_list)  # 测试点
    node_in_graph.append(
        opts.GraphNode(name=one_line_list[0],
                       value=int(one_line_list[1]),
                       symbol_size=int(one_line_list[1]) / 20))  # 手动调整节点的尺寸
#print('-'*20)  # 测试点
link_in_graph = []
for one_line in link_line_list:
    one_line = one_line.strip('\n')
    one_line_list = one_line.split(',')
    #print(one_line_list)  # 测试点
    link_in_graph.append(
        opts.GraphLink(source=one_line_list[0],
                       target=one_line_list[1],
                       value=int(one_line_list[2])))

##--- 第3步:画图
c = Graph()
c.add(
    "",
    node_in_graph,
    link_in_graph,
    edge_length=[10, 50],
    repulsion=5000,
    layout="force",  # "force"-力引导布局,"circular"-环形布局
)
c.set_global_opts(title_opts=opts.TitleOpts(title="关系图-平凡的世界"))
c.render(out_file_name)
node_in_graph = []
for one_line in node_line_list:
    one_line = one_line.strip('\n')
    one_line_list = one_line.split(',')
    node_in_graph.append(
        opts.GraphNode(name=one_line_list[0],
                       value=int(one_line_list[1]),
                       symbol_size=int(one_line_list[1]) / 30))  # 手动调整节点的尺寸

link_in_graph = []
for one_line in link_line_list:
    one_line = one_line.strip('\n')
    one_line_list = one_line.split(',')
    link_in_graph.append(
        opts.GraphLink(source=one_line_list[0],
                       target=one_line_list[1],
                       value=int(one_line_list[2])))

##--- 第3步:画图
c = Graph()
c.add(
    "",
    node_in_graph,
    link_in_graph,
    edge_length=[10, 20],
    repulsion=5000,
    layout="circular",  # "force"-力引导布局,"circular"-环形布局
)
c.set_global_opts(title_opts=opts.TitleOpts(title="关系图-金陵十二钗"))
c.render(out_file_name)