0

I have been using the pydot project to generate graphs showing relations between different data.

import pydot 

graph = pydot.Dot(graph_type='graph') 

for i in range(3):
 edge = pydot.Edge("Root", "Connection%d" % i)
 graph.add_edge(edge)

conn_num = 0
for i in range(3):
 for j in range(2):
  edge = pydot.Edge("Connection%d" % i, "Sub-connection%d" % conn_num)
  graph.add_edge(edge)
  conn_num  += 1

graph.write_png('graph.png')

Running the above code (taken from here) gives me: enter image description here

Question

Is there any way pydot can be configured to work in real time or are there any similar projects like pydot which allow to make graphs in real time? Something which will allow me to add new edges as the data arrives.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2061944
  • 319
  • 1
  • 3
  • 11

1 Answers1

1

Networkx is a python module that specializes in graphs. For visualization, it uses matplotlib.

in matplotlib you can either clear and re-draw the image, or use the animation functions. Clearing and re-drawing is trivial to code. I haven't used the animation functions, but I would expect faster/prettier results, at the cost of more complex code.

Example of a networkx usage: how to draw directed graphs using networkx in python? (or you could use the actual documentation: https://networkx.github.io/)

matplotlib up-date question on SE: Dynamically updating plot in matplotlib

Community
  • 1
  • 1
codeMonkey
  • 410
  • 1
  • 5
  • 13