本文整理汇总了Python中sage.graphs.graph.Graph.get_pos方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.get_pos方法的具体用法?Python Graph.get_pos怎么用?Python Graph.get_pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.get_pos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _spring_layout
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import get_pos [as 别名]
def _spring_layout(self):
r"""
Return a spring layout for the vertices.
The layout is computed by creating a graph `G` on the vertices *and*
sets of the hypergraph. Each set is then made adjacent in `G` with all
vertices it contains before a spring layout is computed for this
graph. The position of the vertices in the hypergraph is the position of
the same vertices in the graph's layout.
.. NOTE::
This method also returns the position of the "fake" vertices,
i.e. those representing the sets.
EXAMPLES::
sage: H = Hypergraph([{1,2,3},{2,3,4},{3,4,5},{4,5,6}]); H
Hypergraph on 6 vertices containing 4 sets
sage: L = H._spring_layout()
sage: L # random
{1: (0.238, -0.926),
2: (0.672, -0.518),
3: (0.449, -0.225),
4: (0.782, 0.225),
5: (0.558, 0.518),
6: (0.992, 0.926),
{3, 4, 5}: (0.504, 0.173),
{2, 3, 4}: (0.727, -0.173),
{4, 5, 6}: (0.838, 0.617),
{1, 2, 3}: (0.393, -0.617)}
sage: all(v in L for v in H.domain())
True
sage: all(v in L for v in H._sets)
True
"""
from sage.graphs.graph import Graph
g = Graph()
for s in self._sets:
for x in s:
g.add_edge(s,x)
_ = g.plot(iterations = 50000,save_pos=True)
# The values are rounded as TikZ does not like accuracy.
return {k:(round(x,3),round(y,3)) for k,(x,y) in g.get_pos().items()}