Ask Your Question
0

Graph plotting not working properly

asked 2022-05-27 17:03:29 +0200

vidyarthi gravatar image

updated 2022-05-29 11:37:50 +0200

slelievre gravatar image

Consider the following code:

def Sier(g):
    h = Graph()
    for i in range(1, g.order() + 1):
        perm = {u: (i, u) for u in g}
        gg = g.relabel(perm=perm, inplace=False)
        h.add_edges(gg.edges())
    return h

f = Sier(graphs.CompleteGraph(4))
v = f.vertices()
n1 = [((a, b), (b, a)) for a, b in v]
n2 = [(a, a), (a, a)) for a, b in v]
x = set(n1) - set(n2)
z = f.add_edges(x)
z.plot()

The plot function does not give the graph I desire. The size() function gives the size correctly. But the diagram is incorrect. Why is this? Any workarounds to make it precise?

edit retag flag offensive close merge delete

Comments

The plot function does not give the graph I desire.

What do you desire, exactly ?

Sorry, I'm not a psychiatrist. I'm just running H sapiens sapiens L. v 1.0, without psychic interface. And my aging dvinatory abilities do leave something to desire...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2022-05-27 23:53:04 +0200 )edit

@Emmanuel Charpentier The plot function above gives me a disconnected graph with less number of edges, quite different from the desired size

vidyarthi gravatar imagevidyarthi ( 2022-05-30 12:50:56 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-05-28 08:12:27 +0200

ortollj gravatar image

updated 2022-05-28 08:40:27 +0200

Hi @vidyarthi

I try to guess, maybe this graph?

def Sier(g):
    h = Graph()
    for i in range(1, g.order() + 1):
        perm = {u: (i, u) for u in g}
        gg = g.relabel(perm=perm, inplace=False)
        h.add_edges(gg.edges())
    return h
f=Sier(graphs.CompleteGraph(4))
v=f.vertices()
n1=[((a,b),(b,a)) for (a,b) in v]
n2=[((a,a),(a,a)) for (a,b) in v]
x=set(n1)-set(n2)
f.add_edges(x)
z=f
z.plot(figsize=14,vertex_size=1000)
edit flag offensive delete link more

Comments

if not, like Emmanuel asked you we need precisions !

I guess @David Coudert answser will help you: editing digraph layout

ortollj gravatar imageortollj ( 2022-05-28 08:15:36 +0200 )edit

and check the construction of the Generalized Sierpinski graphs https://trac.sagemath.org/ticket/33854 (needs review)

David Coudert gravatar imageDavid Coudert ( 2022-05-28 15:49:57 +0200 )edit

@David Coudert yes, what I wanted in my above plot was the Generalized Sierpinski Graph. But, even after trying the code as given in the answer, I am unable to get my desired graph. My graph is connected, whereas the graph plotted is disconnected. And, moreover, the size of graph does not match the construction.

vidyarthi gravatar imagevidyarthi ( 2022-05-30 12:49:51 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-05-27 17:03:29 +0200

Seen: 301 times

Last updated: May 29 '22