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.
Related
I am working on community detection algorithms, and I am currently trying to visualize the results of Louvain algorithm (https://arxiv.org/abs/0803.0476) on a graph of 70K nodes and 8M edges.
I plotted a smaller graph before (20K nodes, 650K edges) with igraph by taking inspiration from How to plot Community-based graph using igraph for python, and it took almost 30 minutes. Plotting 70K nodes and 8M edges takes 8 hours.
To plot the current graph, due to performance, I moved to sfdp (e.g.,
sfdp foo.dot -Goutputorder="edgesfirst" -Goverlap=false -Tpdf -O). However, I am not able to achieve a good layout to highlight distinct communities by distantiating them. I tried to tune both K at graph level, and len and/or weight at edge level (by setting high values for intra-communities edges, e.g., 1000; and low values for inter-community edges, e.g., 1). sfdp seems to ignore weights. Still, as an extension of fdp, it should not.
Examples on a small graph
igraph + fruchterman_reingold layout
sfdp
Am I missing something? How can I highlight community differences as done in the above link?
I'm trying to draw a graph of any network running my script. I use scapy to collect packets and would like to have a node per computer communicating, and an edge per connection.
The issue is I can't find a way to visualize the graph well enough on my screen. So far combining networkx with matlib.pyplot managed to bring the best results, but it still seems pretty random and chaotic, the tags are hard to read, nodes are on top of each other, etc'. It is also preferable to have the ability to interact with the graph - move nodes around, hover over nodes/edges to get extra info, perhaps zoom in or even cluster together nodes so that when you click on the cluster you can see which nodes compose the cluster.
Since analyzing the network data and adding nodes&edges to the graph will be tedious for you to read, I'm adding only the relevant part here (the part that actually shows the graph I built):
pos = nx.spring_layout(Graph, scale=2)
edge_labels = nx.get_edge_attributes(Graph, "Protocol")
nx.draw(Graph,pos, with_labels=True, node_size=600, font_size=8, font_weight='bold')
nx.draw_networkx_edge_labels(Graph, pos, edge_labels=edge_labels, font_size=8)
plt.show()
(I imported networks as nx and matplotlib.pyplot as plt)
I also tried graphviz, ploty and bokeh but couldn't really make them work and after troubleshooting on Google got the impression that anyway they won't fix my problem, and I also tried adjustText - but I could not manage to fit it in my code in any way (can't find how to get the text attribute of my graph) and Holoviews - but it refuses to show an image no matter what I try (even if I copy and paste examples from their site - either python says that '%opts...' is invalid syntax, or if I try changing options any other way the code just runs until it ends and doesn't show anything on the screen.
This is what the graph looks like:
I'm finding a lot of partial solutions online so none of them work, does anybody has a comprehensive solution?
Drawing heavy graphs with plt can be a bit problematic, the problem here is not only with the data, it is also a problem for a human eye to get a lot of information in one look.
My suggestion is to use a more advanced graph visualization library, for example, ipycytoscape. you can define also styles and more features with it that will match your demands
from ipycytoscape import CytoscapeWidget
graph_draw = ipycytoscape.CytoscapeWidget()
graph_draw.graph.add_graph_from_networkx(nx_graph, directed=True)
In addition, if you will use CytoscapeWidget you can interact with the graph and match the focus of the view to the part in the graph that interests you the most.
You can tune the hyper-parameters (k and iterations) of the nx.spring_layout to arrange the nodes. Once you tune the parameters, the connected nodes will be close to each other, and not-contacted nodes will maintain a maximum possible distance.
pos = nx.spring_layout(G,k=0.1, iterations=20)
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.
I'm looking for a way to visualize hierarchical data where there is a many to many relationship between parent and child - this is not a tree, but should be hierarchical like a tree. Is there a good package in R for doing this? I've looked at a few but they're either for visualizing trees or for visualizing graphs, but I'd like to visualize a graph that is also hierarchical.
I think you want to visualise a Directed Acyclic Graph (DAG). I.e. there are no cycles but each node may have multiple in-degree and out-degree. Graph libraries will usually visualise these correctly if you set the right parameters. I would recommend networkx for small/medium-sized graphs, or Gephi for large graphs (gephi is a GUI program but makes good visualisations). Networkx's Graphviz drawing backend will do a good job of drawing DAGs
https://networkx.github.io/documentation/latest/reference/algorithms.dag.html
http://gephi.github.io/
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.