Is this actually a Python/Graphviz question? I’m not really sure of the context, but I would attempt something like:
mygraph = io.StringIO()
mygraph.write("digraph {\n")
for n in nodes:
mygraph.write(f' n{n} [color="{colors[n]}"];\n')
for begin, end in edges:
mygraph.write(f" n{begin} -> n{end};\n")
mygraph.write("}\n")
print(mygraph.getvalue())
yes it is Python/Graphviz question
and currently it works only for small graphs and without color
for huge graphs I receive SIGKILL error but I need to find the solution exactly for huge graphs
from graphviz import Graph
import pandas as pd
df = pd.DataFrame({'ChildID':[1, 1, 2, 3], 'ParentID':[2, 3, 3, 2]})
g = Graph('processs', filename='process.gv')
# run over all the rows and for each row add a new edge to the graph
for index, row in df.iterrows():
g.edge(str(row['ChildID']), str(row['ParentID']))
g.view()
Ah, a different one again. If anything can said to be the official one, it’s probably the in-tree bindings. Though I don’t think any mainstream packaging system actually ships these. So most Python users interact with Graphviz through one of the third party modules mentioned in this thread.
If you want to see if it’s an issue with how graphviz · PyPI is using memory, you could try the method I suggested to construct input and then feed it directly to Graphviz. But there’s always going to be some size limit on what Graphviz can handle determined by the available memory in your computer.
That is a very large graph. And ~20 edges/node (each edge touches 2 nodes) will truly make for a (virtual) printer explosion.
I am not an expert in very large graph, but if it were mine:
start with the sfdp engine (sfdp | Graphviz) It seems to be best suited for very large graphs
separate Python & Graphviz - use Python to create a text Graphviz input file then separately run sfdp (or other engines) on that text input file.
You could also try t-SNE or UMAP to embed the points in 2D space. Really it is not realistic\ to render millions of nodes and edges on a conventional display. How many pixels do you have? What if you wanted to view a text document with millions of words, would you expect to show that on a conventional screen? What’s the goal of this?
it’s not necessarily in pixels, it can be for example in html format (so with zooming in it will be a closer look at exact nodes and their edges)
the goal is to create the best visual representation of such huge graph