python graphviz绘制关系图diagraph

本文介绍如何利用Python的Graphviz库创建和定制Diagraph,详细讲解了node、edge以及Diagraph的属性设置,帮助读者掌握绘制关系图的方法。

 

 

#参数设置请参考http://www.graphviz.org/

from graphviz import Digraph

g = Digraph('e:/tests/测试图片1',format="svg") #png pdf svg多种格式图片

node_count=8

for i in range(node_count):
    g.node(name=str(i),style="filled",color="white",fontcolor="white",fillcolor="#ff6666")


linked=[]
for _ in range(node_count):
    linked.append([])
    
for i in range(node_count):
    for j in range(node_count):
        
        check=True
        
        if i in linked[j]:
            check=False
        
        if j in linked[i]:
            check=False
            
        if i!=j and check:
            g.edge(str(i),str(j),color="#008080")
            linked[i].append(j)
            
print(linked)           

g.view(filename="e:/tests/graphviz_test.svg")

node属性: 

NameDefaultValues
colorblacknode shape color
comment any string (format-dependent)
distortion0.0node distortion for shape=polygon
fillcolorlightgrey/blacknode fill color
fixedsizefalselabel text has no affect on node size
fontcolorblacktype face color
fontnameTimes-Romanfont family
fontsize14point size of label
group name of node’s group
height.5height in inches
labelnode nameany string
layeroverlay rangeall, id or id:id
orientation0.0node rotation angle
peripheriesshape-dependentnumber of node boundaries
regularfalseforce polygon to be regular
shapeellipsenode shape; see Section 2.1 and Appendix E
shapefile external EPSF or SVG custom shape file
sides4number of sides for shape=polygon
skew0.0skewing of node for shape=polygon
style graphics options, e.g. bold, dotted, filled; cf. Section 2.3
URL URL associated with node (format-dependent)
width.75width in inches
z0.0z coordinate for VRML output

edge属性:

NameDefaultValues
arrowheadnormalstyle of arrowhead at head end
arrowsize1.0scaling factor for arrowheads
arrowtailnormalstyle of arrowhead at tail end
colorblackedge stroke color
comment any string (format-dependent)
constrainttrueuse edge to affect node ranking
decorate if set, draws a line connecting labels with their edges
dirforwardforward, back, both, or none
fontcolorblacktype face color
fontnameTimes-Romanfont family
fontsize14point size of label
headlabel label placed near head of edge
headport n,ne,e,se,s,sw,w,nw
headURL URL attached to head label if output format is ismap
label edge label
labelangle-25.0angle in degrees which head or tail label is rotated off edge
labeldistance1.0scaling factor for distance of head or tail label from node
labelfloatfalselessen constraints on edge label placement
labelfontcolorblacktype face color for head and tail labels
labelfontnameTimes-Romanfont family for head and tail labels
labelfontsize14point size for head and tail labels
layeroverlay rangeall, id or id:id
lhead name of cluster to use as head of edge
ltail name of cluster to use as tail of edge
minlen1minimum rank distance between head and tail
samehead tag for head node; edge heads with the same tag are
sametail merged onto the same port
style tag for tail node; edge tails with the same tag are merged onto the same port
taillabel graphics options, e.g. bold, dotted, filled; cf. Section 2.3
tailport label placed near tail of edge n,ne,e,se,s,sw,w,nw
tailURL URL attached to tail label if output format is ismap
weight1

integer cost of stretching an edge

Diagraph属性:

NameDefaultValues
bgcolor background color for drawing, plus initial fill color
centerfalsecenter drawing on page
clusterranklocalmay be global or none
colorblackfor clusters, outline color, and fill color if fillcolor not defined
comment any string (format-dependent)
compoundfalseallow edges between clusters
concentratefalseenables edge concentrators
fillcolorblackcluster fill color
fontcolorblacktype face color
fontnameTimes-Romanfont family
fontpath list of directories to search for fonts
fontsize14point size of label
label any string
labeljustcentered”l” and ”r” for left- and right-justified cluster labels, respectively
labelloctop”t” and ”b” for top- and bottom-justified cluster labels, respectively
layers id:id:id…
margin.5margin included in page, inches
mclimit1.0scale factor for mincross iterations
nodesep.25separation between nodes, in inches.
nslimit if set to f, bounds network simplex iterations by (f)(number of nodes) when setting x-coordinates
nslimit1 if set to f, bounds network simplex iterations by (f)(number of nodes) when ranking nodes
ordering if out out edge order is preserved
orientationportraitif rotate is not used and the value is landscape, use landscape orientation
page unit of pagination, e.g. “8.5,11”
pagedirBLtraversal order of pages
quantum if quantum ¿ 0.0, node label dimensions will be rounded to integral multiples of quantum
rank same, min, max, source or sink
rankdirTBLR (left to right) or TB (top to bottom)
ranksep.75separation between ranks, in inches.
ratio approximate aspect ratio desired, fill or auto
remincross if true and there are multiple clusters, re-run crossing minimization
rotate If 90, set orientation to landscape
samplepoints8number of points used to represent ellipses and circles on output (cf. Appendix C
searchsize30maximum edges with negative cut values to check when looking for a minimum one during network simplex
size maximum drawing size, in inches
style graphics options, e.g. filled for clusters
URL URL associated with graph (format-dependent)

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值