How to use the igraph.drawing function in igraph

To help you get started, we’ve selected a few igraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saezlab / pypath / src / pypath / visual / drawing.py View on Github external
def update_page(self, size=None, margin=None):
        self.dimensions = self.dimensions if size is None else size
        self.margin = self.margin if margin is None else margin
        if type(self.margin) is int:
            self.margin = tuple([self.margin] * 4)
        self.bbox = igraph.drawing.utils.BoundingBox(
            self.margin[0], self.margin[1],
            self.dimensions[0] - self.margin[2],
            self.dimensions[1] - self.margin[3])
github WICI / fastviz / scripts / DynamicGraph_wici.py View on Github external
def plot(self, target, bgcolor, bbox, *args, **kwds):
        if not isinstance(bbox, igraph.drawing.BoundingBox):
            bbox=igraph.drawing.BoundingBox(bbox)
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(bbox.width), int(bbox.height))
        result = igraph.drawing.Plot(target=surface, bbox=bbox)
        ctx = result._ctx
        
        cw, ch = bbox.width/60., bbox.height/60.  
        ctx.set_source_rgba(*result._palette.get(bgcolor))
        ctx.rectangle(0, 0, bbox.width, bbox.height)
        ctx.fill()

        result.add(self.g, bbox.contract((cw, ch, cw, ch)), *args, **kwds)
        result.redraw()
        
        for key in self.labels_dict.keys(): #values():
            if (key=="datetime"):
                self.drawclock(self.labels_dict[key]["label"], ctx, bbox.width-105, 5, 100)
github WICI / fastviz / scripts / DynamicGraph_wici.py View on Github external
def plot(self, target, bgcolor, bbox, *args, **kwds):
        if not isinstance(bbox, igraph.drawing.BoundingBox):
            bbox=igraph.drawing.BoundingBox(bbox)
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(bbox.width), int(bbox.height))
        result = igraph.drawing.Plot(target=surface, bbox=bbox)
        ctx = result._ctx
        
        cw, ch = bbox.width/60., bbox.height/60.  
        ctx.set_source_rgba(*result._palette.get(bgcolor))
        ctx.rectangle(0, 0, bbox.width, bbox.height)
        ctx.fill()

        result.add(self.g, bbox.contract((cw, ch, cw, ch)), *args, **kwds)
        result.redraw()
        
        for key in self.labels_dict.keys(): #values():
            if (key=="datetime"):
                self.drawclock(self.labels_dict[key]["label"], ctx, bbox.width-105, 5, 100)
            else:
                #position
                ctx.move_to(float(self.labels_dict[key]["x"]),float(self.labels_dict[key]["y"]))
github mica-gossip / MiCA / tools / micavis / visual.py View on Github external
def create_plot():
            return igraph.drawing.Plot(cairo_surface, 
                                       (xborder, yborder, 
                                        rect.width - xborder*2, 
                                        rect.height-yborder*2))
github rustyrussell / million-channels-project / src / common / graph.py View on Github external
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)
github saezlab / pypath / src / pypath / visual / drawing.py View on Github external
def make_title(self):
        ctx = cairo.Context(self.plots[-1].surface)
        ctx.set_font_size(self.title_font_size)
        ctx.select_font_face(self.title_font_family, cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)
        ctx.set_source_rgba(*self.rgb1(self.hex2rgb(self.title_color)))
        title_drawer = igraph.drawing.text.TextDrawer(
            ctx, self.title_text, halign=igraph.drawing.text.TextDrawer.CENTER)
        title_drawer.draw_at(0, 40, width=self.bbox.width)
github saezlab / pypath / src / resource_graph.py View on Github external
for i, s in enumerate(escale):
    v1 = g.vs[g.vs['name'].index('%.2f_%u' % (s, 0))]
    v2 = g.vs[g.vs['name'].index('%.2f_%u' % (s, 1))]
    e = g.es[g.get_eid(v1.index, v2.index)]
    e['weight'] = s
    e['label'] = '%.2f' % s
    ycoo =  ymin + yrng * 0.7 + i * 1.8
    lo._coords.append([xleg - xrng * 0.07, ycoo])
    lo._coords.append([xleg + xrng * 0.07, ycoo])
    v1['ncount'] = 0.0
    v2['ncount'] = 0.0
    v1['name'] = ''
    v2['name'] = ''

sf = cairo.PDFSurface('resource_graph_curation-2.pdf', 1024, 1024)
bbox = igraph.drawing.utils.BoundingBox(124, 124, 900, 900)

plot = igraph.plot(g, vertex_label = g.vs['name'],
    layout = lo, 
    bbox = bbox, target = sf, 
    drawer_factory = DefaultGraphDrawerFFsupport, 
    vertex_size = map(lambda x: (x*3)**0.4, g.vs['ncount']), 
    vertex_frame_width = 0, vertex_color = '#6EA945', 
    vertex_label_color = '#777777FF',  vertex_label_family = 'Sentinel Book',
    edge_label_color = '#777777FF', edge_label_family = 'Sentinel Book',
    vertex_label_size = 24,  vertex_label_dist = 1.4, 
    edge_label_size = 24, 
    edge_label = g.es['label'], 
    edge_width = map(lambda x: (x * 0.35)**1.3, g.es['weight']), 
    edge_color = '#007B7F55',
    edge_curved = False)