Network layout optimization¶
- class Orange.network.GraphLayout¶
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.
- coors¶
Coordinates of all vertices. They are initialized to random positions. You can modify them manually or use one of the optimization algorithms. Usage: coors[0][i], coors[1][i]; 0 for x-axis, 1 for y-axis
- set_graph(graph=None, positions=None)¶
Init graph structure.
Parameters: - graph (Orange.netowork.Graph) – Orange network
- positions (A list of positions (x, y)) – Initial node positions
Network optimization
- random()¶
Random graph layout.
- fr(steps, temperature, coolFactor=0, weighted=False)¶
Fruchterman-Reingold spring layout optimization. Set number of iterations with argument steps, start temperature with temperature (for example: 1000).
- fr_radial(center, steps, temperature)¶
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_original()¶
Circular graph layout with original node order.
- circular_random()¶
Circular graph layout with random node order.
- circular_crossing_reduction()¶
Circular graph layout with edge crossing reduction (Michael Baur, Ulrik Brandes).
FragViz
- mds_components(mdsSteps, mdsRefresh, callbackProgress=None, callbackUpdateCanvas=None, torgerson=0, minStressDelta=0, avgLinkage=False, rotationOnly=False, mdsType=0, scalingRatio=0, mdsFromCurrentPos=0)¶
Position the network components according to similarities among them.
- rotate_components(maxSteps=100, minMoment=1e-09, callbackProgress=None, callbackUpdateCanvas=None)¶
Rotate the network components using a spring model.
Helper methods
- get_vertices_in_rect(x1, y1, x2, y2)¶
Return a list of nodes in the given rectangle.
- closest_vertex(x, y)¶
Return the closest node to given point.
- vertex_distances(x, y)¶
Return distances (a list of (distance, vertex) tuples) of all nodes to the given position.
- rotate_vertices(components, phi)¶
Rotate network components for a given angle.
Parameters: - components (list of lists of vertex indices) – list of network components
- phi (float) – list of component rotation angles (unit: radians)
Examples
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[0][u], net_layout.coors[1][u] x2, y2 = net_layout.coors[0][v], net_layout.coors[1][v] plt.plot([x1, x2], [y1, y2], 'b-') # read x and y coordinates to Python list x = net_layout.coors[0] y = net_layout.coors[1] # 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:
