Node Shape
andre-msantos opened this issue · comments
Hi Kay!
Congratulations! Your library is awesome.
Could you help me? I've never used Graphviz before, and I'm having trouble changing the node's shape so that I can save it as an image.
I tried:
Node("a", age=90, shape='diamond')
graph = tree_to_dot(root, node_colour='#0099cc', node_attr='{"shape":"diamond"}')
But these codes didn't work.
Thank you
Hello, thanks for using bigtree!
There is a similar example in the documentation under the tips and trick section here, but the example is for adding edge attributes - for your case it would be to add node attributes.
Below is a sample code on how to have a mixture of DiamondNode and regular Node. I realize there was some bug in the code (thanks to your issue!), I have a fix in bigtree v0.6.8, do update the bigtree package before running the sample code below.
from bigtree import Node, tree_to_dot
class DiamondNode(Node):
def __init__(self, name, **kwargs):
super().__init__(name, **kwargs)
@property
def node_attr(self):
return {"shape": "diamond"}
# Construct tree
root = DiamondNode("a")
b = Node("b", parent=root)
c = Node("c", parent=root)
d = Node("d", parent=b)
graph = tree_to_dot(root, node_attr="node_attr")
graph.write_png("diamond_tree.png")
This will result in the output,
Hope this helps!
Update: In bigtree v0.7.2 I added the node_shape
parameter to quickly customize the node shape.
from bigtree import Node, tree_to_dot
root = Node("a")
b = Node("b", parent=root)
c = Node("c", parent=root)
d = Node("d", parent=b)
graph = tree_to_dot(root, node_shape="diamond")
graph.write_png("diamond_tree.png")
This will result in the output,
Hope this helps!