Exemplo n.º 1
0
def igraphDraw(ig, bbox=(0,0,2000,2000)):
    """
    draw graph using igraph obj
    :param ig: igraph obj
    :return:
    """
    ig.vs["label"] = ig.vs.indices
    drawing.plot(ig, bbox=bbox)
Exemplo n.º 2
0
    def drawgraph(self, gmlfile, giantornot=False):
        "IN:gmlfile path or graph ; choose to draw just giant or not"
        "OUT:the drawing of this graph"
        import igraph as ig
        from igraph.drawing import plot
        print 'Reading graph...'
        if os.path.isfile(str(gmlfile)):
            g = ig.Graph.Read_GML(gmlfile)
        else:
            g = gmlfile
        if giantornot:
            g = ig.clustering.VertexClustering.giant(g.clusters(mode='weak'))

        print 'Ploting graph'
        layout = g.layout(
            'auto'
        )  #[gfr,graphopt,kk,lgl,mds,random,rt_circular,star,sugiyama,auto,circle,drl,fr,grid]
        #         fig = Plot(g,target='atest.png')#Plot(g, layout = layout)
        plot(g, layout=layout)
Exemplo n.º 3
0
 def plotNetwork(self, source: str, target: str, filename: str = None):
     path = self.get_shortest_paths(source, to=target)
     path = path[0]
     path = [(path[i], path[i + 1]) for i in range(len(path) - 1)]
     visual_style = {
         "vertex_label": [n["name"] for n in self.vs],
         "vertex_size": [
             10 if n["name"] == source or n["name"] == target else 5
             for n in self.vs
         ],
         "vertex_label_color":
         [[0, 0, 0, 1] if n["name"] == source else
          [0, 0, 0, 1] if n["name"] == target else [0, 0, 0, 0]
          for n in self.vs],
         "vertex_color":
         [[0, 1, 0, 1] if n["name"] == source else
          [1, 0, 0, 1] if n["name"] == target else [0, 0, 0, 0.2]
          for n in self.vs],
         "edge_color": [[0, 0, 0, 1] if e in path else [0, 0, 0, 0.2]
                        for e in self.get_edgelist()],
     }
     layout_name = "fr"
     bbox = (1000, 1000)
     if filename:
         plot(
             self,
             filename,
             **visual_style,
             vertex_frame_width=0.1,
             layout=self.layout(layout_name),
             bbox=bbox,
             autocurve=True,
         )
     else:
         plot(
             self,
             **visual_style,
             vertex_frame_width=0.1,
             layout=self.layout(layout_name),
             bbox=bbox,
             autocurve=True,
         )
Exemplo n.º 4
0
def gml2svg(gmlfolder, svgfolder):
    fw = open(svgoutpath + 'vecount.txt', 'w')
    svgtype = [
        '_weakGaint', '_strongGaint', '_weakGaintSPT', '_strongGaintSPT'
    ]
    if os.path.exists(svgoutpath) == 0:
        os.mkdir(svgoutpath)
    for file in os.listdir(gmlinpath):
        if os.path.splitext(file)[1] == '.gml':
            print 'Reading graph from ...', file
            if os.path.exists(svgoutpath + file + svgtype[3] + '.2svg'):
                print file, 'has existesed'
                pass
            else:
                try:
                    gmlfile = open(gmlinpath + file)
                    g = ig.Graph.Read_GML(gmlfile)
                    gg = clus.VertexClustering.giant(g.clusters(mode='strong'))
                    es = ig.EdgeSeq(gg)
                    subg = gg.subgraph_edges(es.select(retwitype_eq='0'))
                    es = ig.EdgeSeq(subg)
                    timelist = map(float, es.get_attribute_values('time'))
                    gsp = ig.Graph.spanning_tree(subg, timelist)

                    vecountstr = str(g.vcount()) + '\t' + str(g.ecount(
                    )) + '\t' + str(gg.vcount()) + '\t' + str(
                        gg.ecount()) + '\t' + str(subg.vcount()) + '\t' + str(
                            subg.ecount()) + '\t' + str(
                                gsp.vcount()) + '\t' + str(gsp.ecount())
                    fw.write(file + '\t' + vecountstr + '\n')
                    if os.path.exists(svgoutpath + file + svgtype[3] + '.svg'):
                        print file, 'has existesed'
                    else:
                        print 'Ploting graph'
                        ig.Graph.write_svg(subg,
                                           svgoutpath + file + svgtype[1] +
                                           '.svg',
                                           layout='large')
                        ig.Graph.write_svg(gsp,
                                           svgoutpath + file + svgtype[3] +
                                           '.svg',
                                           layout='large')
                    layout = gsp.layout("large")
                    fig = plot(gsp, layout=layout)
                    plot.show()
            #         ig.Graph.write_svg(gsp, svgoutpath+file+'_w.svg', layout='large')
            #.save(gmlinpath+file+'.fig')
                except Exception, e:
                    print gmlinpath + file, ' failed', e
                    pass
                gmlfile.close()
Exemplo n.º 5
0
import igraph
from igraph.drawing import plot
from color import planar_five_color

color_dict = {0: 'green', 1: 'blue', 2: 'red', 3: 'yellow', 4: 'pink'}

five_regular = igraph.Graph(n=12)
five_reg = [(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 2), (1, 5), (1, 6),
            (1, 7), (2, 3), (2, 7), (2, 8), (3, 4), (3, 8), (3, 9), (4, 5),
            (4, 9), (4, 10), (5, 6), (5, 10), (6, 7), (6, 10), (6, 11), (7, 8),
            (7, 11), (8, 9), (8, 11), (9, 10), (9, 11), (10, 11)]

five_regular.add_edges(five_reg)
graph_colored = planar_five_color(five_regular)
graph_colored.vs['color'] = [
    color_dict[color] for color in graph_colored.vs['color']
]
layout = graph_colored.layout("kk")
plot(graph_colored, target='graph.png', layout=layout)
Exemplo n.º 6
0
def plot_graph(dgraph, name, bbox=(1000, 1000), **kwargs):
    prepare_graph_for_plotting(dgraph)
    drawing.plot(dgraph.g, target=name, bbox=bbox, **kwargs)