spiral_layout

Contents

spiral_layout#

graph_tool.draw.spiral_layout(g, order=None, resolution=0.35, equidistant=False, scale=1.0, pos=None)[git][source]#

Place the vertices along a spiral.

Parameters:
gGraph

Graph to be used.

orderiterable of int (optional, default: None)

The vertices in their order along the spiral, from the center. If not given, the order of the vertex indices is used.

resolutionfloat (optional, default: 0.35)

Angle between consecutive vertices, where smaller values give a more compressed spiral; or, with equidistant=True, the angle of the first vertex.

equidistantbool (optional, default: False)

If True, consecutive vertices are at equal distances.

scalefloat (optional, default: 1.)

Largest absolute coordinate of the centered layout.

posVertexPropertyMap (optional, default: None)

If provided, the positions will be stored in this property map.

Returns:
posVertexPropertyMap

The vertex positions.

See also

circle_layout

Vertices on a circle

shell_layout

Vertices on concentric circles

sphere_layout

Vertices on a sphere

Notes

The \(k\)-th of the \(n\) vertices in the order, with \(k = 0, \dots, n - 1\), is placed at the radius \(k\) and the angle \(k\alpha\), where \(\alpha\) is resolution (an Archimedean spiral),

\[\boldsymbol x_k = k\left(\cos k\alpha, \sin k\alpha\right),\]

or, with equidistant=True, on the spiral \(r = \theta/2\) at unit Euclidean distances,

\[\boldsymbol x_k = \frac{\theta_k}{2}\left(\cos\theta_k, \sin\theta_k\right), \qquad |\boldsymbol x_{k+1} - \boldsymbol x_k| = 1, \qquad \theta_0 = \alpha,\]

where \(\theta_{k+1}\) is the smallest angle larger than \(\theta_k\) that satisfies the equation, which is found numerically, starting from the angle at unit arc length along the spiral (which the root cannot precede, since a chord is not longer than its arc).

The layout is then centered at the mean position and scaled so that its largest absolute coordinate is scale (unless \(n < 2\), in which case the vertex is placed at the origin). The edges are ignored.

Examples

>>> g = gt.collection.data["karate"]
>>> pos = gt.spiral_layout(g)
>>> gt.graph_draw(g, pos=pos, output="karate-spiral.pdf")
<...>
../_images/karate-spiral.png

Spiral layout of the karate club network.#