This example is given on the website but there is no mention about how to set the colours using dictionaries.
import pygraphviz as pgv
d={'1': {'2': None}, '2': {'1': None, '3': None}, '3': {'2': None}}
A=pgv.AGraph(d)
Are you supposed to use get_node after initialising via AGraph ?
Found out that you should use effectively get_node() and pass the id to find the node. Also found out that you need to set the style of the graph to filled or you will not see the fill colour.
import pygraphviz as pgv
from PIL import Image
d={'1': {'2': None}, '2': {'1': None, '3': None}, '3': {'2': None}}
A=pgv.AGraph(d)
A.node_attr['style']='filled'
n = A.get_node('1')
n.attr['fillcolor']="#CCCCFF"
n.attr['label'] = 'MY LOVELY LABEL'
A.layout() # default to neato
A.layout(prog='dot') # use dot
A.draw('file.png')
img = Image.open('file.png')
img.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With