Hi !
I am using the Python module for Graphviz and I am facing an issue when creating a “directed graph” with colors.
The graph doesn’t seem to display correctly when colored gradients are added inside the node attributes function. For some reason, both the labels and the edges disappear.
-
without gradients: G1 hosted at ImgBB — ImgBB
-
with gradients: G2 hosted at ImgBB — ImgBB
The corresponding minimal example:
# Dictionary storing relations between nodes
d = {0: set([1, 2, 3]),
1: set([4, 5, 6]),
2: set([7, 8, 9, 10]),
3: set([0]),
4: set([]),
5: set([]),
6: set([]),
7: set([]),
8: set([0]),
9: set([]),
10: set([])}
# List of node labels (3 labels per node)
l = [('S', 'M', 'S'),
('M', 'S', 'L'),
('M', 'S', 'S'),
('M', 'S', 'M'),
('S', 'L', 'L'),
('S', 'L', 'M'),
('S', 'L', 'X'),
('S', 'S', 'S'),
('S', 'S', 'M'),
('S', 'S', 'L'),
('S', 'S', 'X')]
# Dictionary storing the colors corresponding to each label
c = {'S':'olivedrab1',
'M':'mediumturquoise',
'L':'deepskyblue',
'X':'palevioletred1'}
# Create a "directed graph" with general node and edge attributes
G = Digraph(node_attr={'shape':'record',
'style':'rounded, filled',
'color':'white',
'height':'0.1',
'nodesep':'0.1', #not working
'ranksep':'0.1', #not working
'fontcolor':'black',
'fontsize':'14.0',
'fontpath':'C:/windows/fonts',
'fontname':'consolas'},
edge_attr={'color':'grey',
'arrowhead':'vee',
'len':'0.1',
'label':'',
'penwidth':'0.1',
'weight':'1.2'} #not working
)
# 1st pass: create all nodes (0 to 10)
for k in d:
l1, l2, l3 = P[k]
# set specific attribute to each node (label & colors)
G.attr('node', label='{} | {} | {}'.format(l1, l2, l3))# !!! PROBLEM when adding -> fillcolor='%s:%s' % (c[l1], c[l3]))
G.node(str(k))
# 2nd pass: create edges between nodes
for k in d:
for i in d[k]:
G.edge(str(k), str(i))
I am all new to Graphviz and the DOT language in general, am I doing something wrong or is it a bug ?