1

I have a question about pydot. I created some nodes and connected them to other nodes. While making connections, I gave a label to the edges. How can we change the direction of these labels ?(eg parallel to the line).My code;

graph = pydot.Dot(graph_type='digraph')
graph.add_node(pydot.Node('TOP', label='Weather'))
graph.add_node(pydot.Node('M1', label='t-shirt'))
graph.add_node(pydot.Node('M2', label='jacket'))
graph.add_node(pydot.Node('M3', label='umbrella'))
edge = pydot.Edge('TOP', 'M1', label = 'sunny')
graph.add_edge(edge)
edge = pydot.Edge('TOP', 'M2', label = 'windy')
graph.add_edge(edge)
edge = pydot.Edge('TOP', 'M3', label = 'rainy')
graph.add_edge(edge)
graph.write_png('output.png')

output picture

1 Answer 1

1

An option might be to change the layout with the rankdir attribute.

graph = pydot.Dot(graph_type='digraph',rankdir="LR")

which results in

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.