Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I often find that bumping up the number of iterations helps. For example,

sage: g = graphs.MycielskiGraph(4)
sage: p = g.plot()
sage: p.save("g1.png")

gives

misshapen

but

sage: g = graphs.MycielskiGraph(4)
sage: p = g.plot(layout='spring', iterations=10000)
sage: p.save("g2.png")

gives

nice

More generally, you can control the positions of where the nodes are by using a position dictionary, and you can save the current positions to start from. For example:

sage: p = g.plot(layout='spring', iterations=10000, save_pos=True)
sage: g.get_pos()
{0: [1.3716897101521048, -0.02830881780686272], 1: [1.211732997569143, 0.41733909879317593], 2: [1.0618077247691025, -0.5105153130614829], 3: [0.9519193694209523, 0.2027868664651152], 4: [1.674575908225974, -0.3855530203902292], 5: [1.8974214150303133, 0.20135568451141017], 6: [2.3146717824436642, -0.2518256884495827], 7: [1.6466675751821391, 0.7744402171620497], 8: [1.4420671784710155, -0.9954885089922162], 9: [0.7102586964467139, 0.7529303543692121], 10: [0.5362226032745113, -0.1771608726005901]}

So we can store and modify this information, so that

g = graphs.MycielskiGraph(4)
p = g.plot(layout='spring', iterations=10000, save_pos=True)
pos = (g.get_pos())
pos[10] = (2, 2)
g.delete_vertex(0)
p = g.plot(pos=pos, save_pos=True)
p.save("g3.png")

gave me

image description

I often find that bumping up the number of iterations helps. For example,

sage: g = graphs.MycielskiGraph(4)
sage: p = g.plot()
sage: p.save("g1.png")

gives

misshapen

but

sage: g = graphs.MycielskiGraph(4)
sage: p = g.plot(layout='spring', iterations=10000)
sage: p.save("g2.png")

gives

nice

More generally, you can control the positions of where the nodes are by using a position dictionary, and you can save the current positions to start from. For example:

sage: p = g.plot(layout='spring', iterations=10000, save_pos=True)
sage: g.get_pos()
{0: [1.3716897101521048, -0.02830881780686272], 1: [1.211732997569143, 0.41733909879317593], 2: [1.0618077247691025, -0.5105153130614829], 3: [0.9519193694209523, 0.2027868664651152], 4: [1.674575908225974, -0.3855530203902292], 5: [1.8974214150303133, 0.20135568451141017], 6: [2.3146717824436642, -0.2518256884495827], 7: [1.6466675751821391, 0.7744402171620497], 8: [1.4420671784710155, -0.9954885089922162], 9: [0.7102586964467139, 0.7529303543692121], 10: [0.5362226032745113, -0.1771608726005901]}

So And thus we can store and modify this information, so that

g = graphs.MycielskiGraph(4)
p = g.plot(layout='spring', iterations=10000, save_pos=True)
pos = (g.get_pos())
pos[10] = (2, 2)
g.delete_vertex(0)
p = g.plot(pos=pos, save_pos=True)
p.save("g3.png")

gave me

image description

I often find that bumping up the number of iterations helps. For example,

sage: g = graphs.MycielskiGraph(4)
sage: p = g.plot()
sage: p.save("g1.png")

gives

misshapen

but

sage: g = graphs.MycielskiGraph(4)
sage: p = g.plot(layout='spring', iterations=10000)
sage: p.save("g2.png")

gives

nice

More generally, you can control the positions of where the nodes are by using a position dictionary, and you can save the current positions to start from. For example:

sage: p = g.plot(layout='spring', iterations=10000, save_pos=True)
sage: g.get_pos()
{0: [1.3716897101521048, -0.02830881780686272], 1: [1.211732997569143, 0.41733909879317593], 2: [1.0618077247691025, -0.5105153130614829], 3: [0.9519193694209523, 0.2027868664651152], 4: [1.674575908225974, -0.3855530203902292], 5: [1.8974214150303133, 0.20135568451141017], 6: [2.3146717824436642, -0.2518256884495827], 7: [1.6466675751821391, 0.7744402171620497], 8: [1.4420671784710155, -0.9954885089922162], 9: [0.7102586964467139, 0.7529303543692121], 10: [0.5362226032745113, -0.1771608726005901]}

And thus we can store and modify this information, so that

g = graphs.MycielskiGraph(4)
p = g.plot(layout='spring', iterations=10000, save_pos=True)
pos = (g.get_pos())
pos[10] = (2, 2)
g.delete_vertex(0)
p = g.plot(pos=pos, save_pos=True)
p.save("g3.png")

gave me

image description