[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Plotting graph on cairo surface in Python
From: |
Tamás Nepusz |
Subject: |
Re: [igraph] Plotting graph on cairo surface in Python |
Date: |
Mon, 18 Jun 2012 17:25:51 +0200 |
Hi Stephen,
The first catch is that igraph.plot() _constructs_ the plot itself (i.e. it
returns a Plot instance) but it does not draw it yet on the surface you
specified. This is probably an oversight on my side because igraph.plot() would
draw the graph if the target you specify is a string (i.e. a filename) or None
(meaning to plot the graph into a temporary file and show that). The workaround
for the time being is to do this:
plot = igraph.plot(g, surface, bbox=(width, height), layout=layout)
plot.redraw()
The next thing you should do is to ensure that the plot igraph will draw also
has a transparent background (it is white by default):
plot = igraph.plot(g, surface, bbox=(width, height), layout=layout)
plot.background = None
plot.redraw()
This should do the trick. As igraph 0.6 has just been released, I cannot fix
the bug with igraph.plot in the 0.6 branch, but I will make sure that 0.7 does
not have this bug.
Best,
Tamas
> I'm using the Python igraph bindings and would like to plot my graph
> with a transparent background. I think I need to use
> igraph.Graph.plot's support for a Cairo surface target. Can anyone
> point me at an example of plotting a graph to a cairo surface, or else
> is there a better way to do this? The below code snippet shows the
> approach I'm trying to get to work. The output image is transparent,
> but there's no graph.
>
> Thanks for the library. I've gotten a lot of miles out of it on a wide
> variety of network analysis and visualization projects.
>
> Steve
>
> import igraph,cairo
> g = igraph.Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0),
> (6,3), (5,6)])
> layout = g.layout('kk')
> width,height = 900,600
> surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
> ctx = cairo.Context(surface)
> ctx.scale(width,height)
> ctx.rectangle(0, 0, 1, 1)
> ctx.set_source_rgba(0,0,0,0)
> ctx.fill()
> igraph.plot(g,surface,bbox=(width,height),layout=layout)
> surface.write_to_png('example.png')
>
> _______________________________________________
> igraph-help mailing list
> address@hidden (mailto:address@hidden)
> https://lists.nongnu.org/mailman/listinfo/igraph-help