draw a large graph with many nodes and edges with igraph - python

I'm trying to visualize a big data set of nodes and edges and I have two files: nodes.txt and edges.txt and I want draw a graph for them. it's got 403,394 nodes and 3,387,388 edges. good to know I generate them randomly.
So I decide using igraph python to draw it by layout and plot but when I try to draw a simple graph with few edges it works but with this huge data set it got an memory error and doesn't work right. I want some help to draw a graph from my edge list with igraph. or maybe there is some better way to do, so suggest it to me.
I use layout with Drl algorithm and use the function plot.

Related

Visualizing a medium size graph in python

I have a medium sized graph with ~400 nodes and ~6000 edges that I am trying to visualize via python. At the moment I am trying to use networkx and this is the output.
There's 2 issues:
The layout seems to be too dense and I can't make out any of the edges near the center of the graph
There's a set of nodes that are semi-bipartite (they have no edges within themselves), and I would like to place these nodes on a vertical line on the right, and all the other nodes on the left. I can't figure out how to manage this with networkx.
Any help would be appreciated, thanks!
I suggest you experiment with different engines other that dot. Consider neato, twopi or circo. The gallery section on the official graphviz site has really nice examples (300+ nodes) that you can mimic.

Matplotlib circle as arrowhead

I am working on a plotting tool for graphs and want to use use circles as arrowheads for FancyArrowPatch when connecting to nodes, like this:
Also I would like to allow three different styles: "o--o", "o--" and "--o".
Is there is a generic way to use Patch objects as arrowheads?
My alternative approach would be to use small circle patches and manually plot them on top of the edges right before the nodes. But this would include calculating the correct coordinates when dealing with curved edges which I would like to avoid. I have already read this answer, but as far as I understand it, the solution won't work with FancyArrowPatch.
Thanks in advance.

Reuse result of stochastic python-igraph layout for future plotting

I can successfully draw a nice network using the kk layout. Unfortunately, as kk is a stochastic layout, it looks different every time I plot it.
Is there a way to plot it twice with the same vertex and node arrangement but varying the visual style? I would like to visualize changes by changing the vertex colors and showing both plots side-by-side. Of course, in the future I might be interested in modifying edges too but this is not an issue right now.
I'm completely fine with the fact that the layout changes for every run of my programm, it should just plot it consistently within one run.
I can plot it twice if I save the resulting SVG but of course modyfining the underlying graph would be more elegant than just tweaking the raw SVG.
This plots the same layout twice but only as SVG:
s = cairo.SVGSurface(None, 800, 800)
model = ig.plot(g, **visual_style,
vertex_label=[label_for_title(vertex[1]['title']) for vertex in enumerate(g.vs)],
edge_color=[color_for_rating(edge[1]['rating']) for edge in enumerate(g.es)],
target=s,
mark_groups=action_systems)._repr_svg_()
display(SVG(model))
display(SVG(model))
Yes, there is, because igraph lets you store the layout of the vertices as an object: my_layout = g.layout('kk').
So you can plot your graph g multiple times with the same layout:
my_layout = g.layout('kk')
igraph.plot(g,layout=my_layout)
#now change g and/or the visual style
g.delete_edges([0,3,4])
igraph.plot(g,layout=my_layout,vertex_color=['blue' for _ in g.vs])
The new plotted graph will have the same vertex positions but now a few edges will be gone and all the vertices will be blue, naturally.

Drawing clustered graphs in Python

I already have a way of clustering my graph, so the process of clustering isn't the issue here. What I want to do is, once we have all the nodes clustered - to draw the clustered graph in Python, something like this:
I looked into networkx, igraph and graph-tool, but they seem to do the clustering, but not the drawing. Any ideas and propositions of what library should I use for drawing the already clustered graph, which will minimize the number of crossing links?
Take a look at GraphViz
http://www.graphviz.org/Gallery/directed/cluster.html
There's a Python binding for that, but I have to say I always create the text files directly as they're easy enough to write. Don't be fooled by the plain-looking examples, every aspect of your graph is highly customizable and you can make some pretty nifty graph visualizations with it. Not sure about nested clusters though, never tried that out.

Graphviz: how to insert two new linked nodes and minimize edge crossings?

I have the following graph :
As you can see, there are two natural clusters. I would like to figure out a way to separate these clusters into two graphs.
The key step, of course, is to compute the right split. I would like to insert two nodes n1 & n2, link them e(n1, n2), and move them around, minimizing the number of edge crossings (of course fixing all nodes/edges exactly where they are).
Can anyone offer any help here? I don't think graphviz has anything that enables me to do it.
I think you mingle two different tasks here: the one is Analysis of a graph, the other one is Visualization of the same.
Graphviz, as the name suggests, is a tool for visualization of graphs. Visualization can take many forms, typically one tries to "make it look good" by having those nodes close to each other that are connected, thus reducing the visual edge lengths. One can utilize some spring- or gravitational model to calculate optimal positions for all nodes. Other options include circular- or shell-layouts.
A certain visualization should not be the basis for the analysis of a graph. Graph properties, like average shortest path length or clustering coefficient, are independent of any visualization.
You say you want to "minimize the number of edge crossings". The number of edge crossings is a property of your visualization, not of your graph! It probably changes each time you let graphviz calculate the layout, even if the graph is unchanged. Who says that 2d is the only possible representation of your graph? Add just one dimension, and you won't have any edge crossing.
I'd recommend to concentrate on graph analysis. I don't know if you're aware of NetworkX. They have dozens of Algorithms to analyze your graph. Maybe the clustering and clique sections are of interest to you.

Categories