I have a tree which I plot with Graphviz, however the distances between the nodes is very large and not efficiently used. Can this be improved?
I tried playing with mindist
, splines
and overlap
, but nothing seems to work. Is this the best graphviz is able to do?
The data:
The code:
import json
import pygraphviz as pgv
# Read data from the "graph1.json" file
with open("graph2.json") as f:
edges_data = json.load(f)
# Create a new directed graph
graph = pgv.AGraph(strict=False, directed=True)
# Add nodes and edges to the graph based on the JSON data
for edge in edges_data:
graph.add_node(edge["ID"])
if edge["ParentID"]:
graph.add_edge(edge["ParentID"], edge["ID"])
graph_attrs = {
'dpi': 50,
'root': 10000185,
'mindist': 0.1
# 'splines': False, # false
# 'overlap':'scale' # false
}
graph.graph_attr.update(graph_attrs)
graph.draw("output_graph.svg", prog="circo", format="svg")
You have probably hit this circo bug:
Trying to find a circo work-around will probably not lead to success (unless you feel lucky)
Try the other layout engines, twopi, neato, fdp, and dot