Reputation: 2220
I am trying to draw graph with different colours edges by using graphviz in Python. I am creating colour list and using in edge colour. However, it looks like it does not support in graphviz. I am not sure how to set different colour of edges. Here is my code:
import graphviz as gv
d = gv.Digraph()
colors = ['green','red']
d.attr('edge', color = colors)
d.edge('hello','world')
d.edge('world','hello')
d.view()
Looking for valuable comments. Thanks
Upvotes: 4
Views: 8672
Reputation: 1327
import graphviz as gv
colors = ['green','red']
def create_graph(colors, d):
d.edge('hello','world', color=colors[0])
d.edge('world','hello', color=colors[1])
d.view()
if __name__ == '__main__':
d = gv.Digraph()
create_graph(colors, d)
Upvotes: 7
Reputation: 56586
I don't really know the python wrapper for graphviz,but if by different colour of edges you mean multiple colors (?), you may try the following:
d.attr('edge', color = 'green:red')
Otherwise, if you'd like to have a green and a red edge, the following may work:
d.edge('hello','world', color='green' )
d.edge('world','hello', color='red' )
Upvotes: 2