def draw_graph():
    nodes = [{
        "name": "结点1",
        "symbolSize": 10
    }, {
        "name": "结点2",
        "symbolSize": 20
    }, {
        "name": "结点3",
        "symbolSize": 30
    }, {
        "name": "结点4",
        "symbolSize": 40
    }, {
        "name": "结点5",
        "symbolSize": 50
    }, {
        "name": "结点6",
        "symbolSize": 40
    }, {
        "name": "结点7",
        "symbolSize": 30
    }, {
        "name": "结点8",
        "symbolSize": 20
    }]
    links = []
    for i in nodes:
        for j in nodes:
            links.append({"source": i.get('name'), "target": j.get('name')})
    graph = Graph("关系图-环形布局示例")
    graph.add("",
              nodes,
              links,
              is_label_show=True,
              repulsion=8000,
              layout='circular',
              label_text_color=None)
    graph.show_config()
    graph.render()
Exemple #2
0
def graph_show(edge_list):
    nodes = []
    links = []
    nodes_list = []
    w_min = sys.float_info.max
    w_max = 0
    for edge in edge_list:
        u, v, w = edge.getLeft(), edge.getRight(), edge.getWeight()

        if w < w_min:
            w_min = w
        if w > w_max:
            w_max = w

        if u not in nodes_list:
            nodes_list.append(u)
            nodes.append({"name": str(u), "symbolSize": 10})

        if v not in nodes_list:
            nodes_list.append(v)
            nodes.append({"name": str(v), "symbolSize": 10})

        links.append({"source": str(u), "target": str(v), "value": w})

    print("min w:", w_min)
    print("max w:", w_max)
    graph = Graph("Minimum Spanning Tree")
    graph.add("",
              nodes,
              links,
              graph_layout='force',
              graph_edge_length=[w_min, w_max],
              graph_gravity=0,
              graph_repulsion=0,
              is_label_show=True)
    graph.show_config()
    graph.render()
Exemple #3
0
def test_graph():

    # graph_0
    nodes = [{"name": "结点1", "symbolSize": 10},
             {"name": "结点2", "symbolSize": 20},
             {"name": "结点3", "symbolSize": 30},
             {"name": "结点4", "symbolSize": 40},
             {"name": "结点5", "symbolSize": 50},
             {"name": "结点6", "symbolSize": 40},
             {"name": "结点7", "symbolSize": 30},
             {"name": "结点8", "symbolSize": 20}]
    links = []
    for i in nodes:
        for j in nodes:
            links.append({"source": i.get('name'), "target": j.get('name')})
    graph = Graph("关系图-力引导布局示例")
    graph.add("", nodes, links, repulsion=8000)
    graph.show_config()
    graph.render()

    # graph_1
    graph = Graph("关系图-环形布局示例")
    graph.add("", nodes, links, is_label_show=True,
              graph_repulsion=8000, graph_layout='circular', label_text_color=None)
    graph.show_config()
    graph.render()

    # graph_2
    import json
    if PY2:
        import codecs
        with codecs.open(os.path.join("..", "json", "weibo.json"), "rb") as f:
            j = json.load(f)
    else:
        with open(os.path.join("..", "json", "weibo.json"), "r", encoding="utf-8") as f:
            j = json.load(f)
    nodes, links, categories, cont, mid, userl = j
    graph = Graph("微博转发关系图", width=1200, height=600)
    graph.add("", nodes, links, categories, label_pos="right", graph_repulsion=50,
              is_legend_show=False, line_curve=0.2, label_text_color=None)
    graph.show_config()
    graph.render()
Exemple #4
0
def test_graph():

    # graph_0
    nodes = [{"name": "结点1", "symbolSize": 10},
             {"name": "结点2", "symbolSize": 20},
             {"name": "结点3", "symbolSize": 30},
             {"name": "结点4", "symbolSize": 40},
             {"name": "结点5", "symbolSize": 50},
             {"name": "结点6", "symbolSize": 40},
             {"name": "结点7", "symbolSize": 30},
             {"name": "结点8", "symbolSize": 20}]
    links = []
    for i in nodes:
        for j in nodes:
            links.append({"source": i.get('name'), "target": j.get('name')})
    graph = Graph("关系图-力引导布局示例")
    graph.add("", nodes, links, repulsion=8000)
    graph.show_config()
    graph.render()

    # graph_1
    graph = Graph("关系图-环形布局示例")
    graph.add("", nodes, links, is_label_show=True, repulsion=8000, layout='circular', label_text_color=None)
    graph.show_config()
    graph.render()

    # graph_2
    import json
    if PY2:
        import codecs
        with codecs.open(os.path.join("..", "json", "weibo.json"), "rb") as f:
            j = json.load(f)
    else:
        with open(os.path.join("..", "json", "weibo.json"), "r", encoding="utf-8") as f:
            j = json.load(f)
    nodes, links, categories, cont, mid, userl = j
    graph = Graph("微博转发关系图", width=1200, height=600)
    graph.add("", nodes, links, categories, label_pos="right", repulsion=50, is_legend_show=False, line_curve=0.2,
              label_text_color=None)
    graph.show_config()
    graph.render()
Exemple #5
0
from pyecharts import Graph
import json
with open("..jsonweibo.json", "r", encoding="utf-8") as f:
    j = json.load(f)
    nodes, links, categories, cont, mid, userl =i j 
    graph =Graph("微博转发关系图", width=1200, height=600)
    graph.add("", nodes, links, categories, label_pos="right", repulsion=50, is_legend_show=False, line_curve=0.2, label_text_color=None)
    graph.show_config()
    graph.render()