A class for graph layout optimization. Before using any of the layout optimization technique, the class have to be initialized with the set_graph method. Also, do not forget to call set_graph again if the graph structure changes.
Coordinates of all vertices. They are initialized to random positions. You can modify them manually or use one of the optimization algorithms. Usage: coors[i], coors[i]; 0 for x-axis, 1 for y-axis
Init graph structure.
Random graph layout.
Fruchterman-Reingold spring layout optimization. Set number of iterations with argument steps, start temperature with temperature (for example: 1000).
Radial Fruchterman-Reingold spring layout optimization. Set center node with attribute center, number of iterations with argument steps and start temperature with temperature (for example: 1000).
Circular graph layout with original node order.
Circular graph layout with random node order.
Circular graph layout with edge crossing reduction (Michael Baur, Ulrik Brandes).
Position the network components according to similarities among them.
Rotate the network components using a spring model.
Return a list of nodes in the given rectangle.
Return the closest node to given point.
Return distances (a list of (distance, vertex) tuples) of all nodes to the given position.
Rotate network components for a given angle.
Network constructor and random layout
In our first example we create a Network object with a simple full graph (K5). Vertices are initially placed randomly. Graph is visualized using pylabs matplotlib.
import Orange.network from matplotlib import pyplot as plt # vertices are placed randomly in Network constructor net = Orange.network.Graph() net.add_nodes_from(range(5)) # set edges for i in range(4): for j in range(i + 1, 5): net.add_edge(i, j) net_layout = Orange.network.GraphLayout() net_layout.set_graph(net) # read all edges and plot a line for u, v in net.edges(): x1, y1 = net_layout.coors[u], net_layout.coors[u] x2, y2 = net_layout.coors[v], net_layout.coors[v] plt.plot([x1, x2], [y1, y2], 'b-') # read x and y coordinates to Python list x = net_layout.coors y = net_layout.coors # plot vertices plt.plot(x, y, 'ro') plt.savefig("network-constructor-nx.png")
Executing the above saves a pylab window with the following graph drawing:
Network layout optimization
This example demonstrates how to optimize network layout using one of the included algorithms.
part of network-optimization-nx.py
# vertices are placed randomly in NetworkOptimization constructor net_layout = Orange.network.GraphLayout() net_layout.set_graph(net) # optimize verices layout with one of included algorithms net_layout.fr(100, 1000)
The result of the above script is a spring force layout optimization: