subgraph creates duplicate edges

43 views
Skip to first unread message

watson ix

unread,
Apr 11, 2014, 7:55:24 PM4/11/14
to pygraphvi...@googlegroups.com
I cannot figure out how to create a subgraph off an existing graph without creating duplicate edges. For instance:

G = GV.AGraph(strict=False,directed=True)
G.add_edge('a','b')
G.add_edge('a','c')
G.add_edge('c','a')
G.to_string()
G.subgraph('a','b'),rank='same')
print G.to_string()
digraph  {
	{
		graph [rank=same];
		a -> b;
	}
	a -> b;
	a -> c;
	c -> a;
}

Which graphviz draws as: 




Whereas I intended it to wind up with something which looks like this:




This can be done if instead the output were:
digraph  {
	{
		graph [rank=same];
		a;b;
	}
	a -> b;
	a -> c;
	c -> a;
}



Aric Hagberg

unread,
Apr 11, 2014, 8:57:07 PM4/11/14
to pygraphvi...@googlegroups.com
Adding a subgraph that way makes a node-induced subgraph (i.e. adds the edges again).
You can do it this way to without adding the edges.

import pygraphviz as pgv                                                        
G = pgv.AGraph(strict=False,directed=True)                                      
G.add_edge('a','b')                                                             
G.add_edge('a','c')                                                             
G.add_edge('c','a')                                                             
G.to_string()                                                                   
S = G.subgraph(rank='same')                                                     
S.add_nodes_from(['a','b'])                                                     
print G.to_string() 

Aric


--
You received this message because you are subscribed to the Google Groups "pygraphviz-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pygraphviz-disc...@googlegroups.com.
To post to this group, send email to pygraphvi...@googlegroups.com.
Visit this group at http://groups.google.com/group/pygraphviz-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages