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

Matthias Berndt
  • 4,387
  • 1
  • 11
  • 25

1 Answers1

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

abc
  • 11,579
  • 2
  • 26
  • 51