[英]How to visualize a graph with nodes divided in 2 clusters, edges should be present between the clusters and within the clusters , using python?
I wanted to generate a graph that looks similar to this.我想生成一个与此类似的图表。
But For my code, I'm getting a graph like the one below但是对于我的代码,我得到了如下图
I have entered the following code by importing graphviz.我通过导入graphviz输入了以下代码。 I request somebody to help me make changes in it to get the required code.
我请求有人帮助我对其进行更改以获得所需的代码。
from graphviz import Graph
g = Graph('G', filename='cluster.gv')
a=['1','2','3','4']
b=['5','6','7','8']
with g.subgraph(name='cluster_0') as c:
c.attr(color='lightgrey')
c.node_attr.update(style='filled', color='red')
for i in a:
c.node(str(i),shape='circle')
c.attr(label='partition #1')
with g.subgraph(name='cluster_1') as c:
c.attr(color='lightgrey')
c.node_attr.update(style='filled', color='blue')
for i in b:
c.node(str(i),shape='circle')
c.attr(label='partition #2')
g.edge('1','5')
g.edge('1','3')
g.edge('2','7')
g.edge('5','8')
g.view()
Thanks in advance提前致谢
This program:这个程序:
digraph ovaltest {
graph [splines=line]
node [color=red shape=box style=rounded height=.2 width=.2 ]
p1_1 [pos="70,95" ]
p1_2 [pos="120,95" ]
p1_3 [pos="170,95" ]
p1_4 [pos="220,95" ]
p2_1 [pos="70,70" ]
p2_4 [pos="220,70" ]
p3_1 [pos="70,45" ]
p3_4 [pos="220,45" ]
p4_1 [pos="70,20" ]
p4_2 [pos="120,20" ]
p4_3 [pos="170,20" ]
p4_4 [pos="220,20" ]
node [color=blue shape=box style=rounded height=.2 width=.2 ]
q1_1 [pos="350,95" ]
q1_2 [pos="400,95" ]
q1_3 [pos="450,95" ]
q2_1 [pos="350,70" ]
q2_3 [pos="450,70" ]
q3_1 [pos="350,45" ]
q3_3 [pos="450,45" ]
q4_1 [pos="350,20" ]
q4_2 [pos="400,20" ]
q4_3 [pos="450,20" ]
p2_1 -> p3_4 [dir="none"]
p2_4 -> q1_2 [dir="none"]
p2_4 -> q3_3 [dir="none"]
p4_4 -> q4_1 [dir="none"]
}
And this command line:这个命令行:
neato -n -Tpng yourfile.gv >yourfile.png neato -n -Tpng yourfile.gv >yourfile.png
produces this graph :产生这个图:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.