graphviz segmentation fault

2024/10/14 19:30:16

I'm building a graph with many nodes, around 3000. I wrote a simple python program to do the trick with graphviz, but it gives me segmentation fault and I don't know why, if the graph is too big or if i'm missing something.

The code is:

#!/usr/bin/env python# Import graphviz
import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz')
import gv# Import pygraph
from pygraph.classes.graph import graph
from pygraph.classes.digraph import digraph
from pygraph.algorithms.searching import breadth_first_search
from pygraph.readwrite.dot import write# Graph creation
gr = graph()file = open('nodes.dat', 'r')
line = file.readline()
while line:gr.add_nodes([line[0:-1]])line = file.readline()file.close()
print 'nodes finished, beginning edges'edges = open('edges_ok.dat', 'r')
edge = edges.readline()
while edge:gr.add_edge((edge.split()[0], edge.split()[1]))edge = edges.readline()edges.close()
print 'edges finished'
print 'Drawing'# Draw as PNG
dot = write(gr)
gvv = gv.readstring(dot)
gv.layout(gvv,'dot')
gv.render(gvv,'svg','graph.svg')

and it crashes at the gv.layout() call.

The files are somthing like: nodes:

   node1node2node3

edges_ok:

   node1 node2node2 node3
Answer

I changed the layout type from dot to neato and that solved the problem.

I searched a bit and it seems that the dot layout is a bit faulty on large graphs.

https://en.xdnf.cn/q/69381.html

Related Q&A

how to pass char pointer as argument in ctypes python

Please help me in converting below line of c++ code into ctypes python:Ret = openFcn(&Handle, "C:\\Config.xml");below are the declarations of each:typedef uint16_t (* OpenDLLFcnP)(void **…

Restarting a Python Interpreter Quietly

I have a python interpreter embedded inside an application. The application takes a long time to start up and I have no ability to restart the interpreter without restarting the whole application. What…

Unique lists from a list

Given a list I need to return a list of lists of unique items. Im looking to see if there is a more Pythonic way than what I came up with:def unique_lists(l):m = {}for x in l:m[x] = (m[x] if m.get(x) !…

How to run Spyder with Python 3.7 with Anaconda

I have installed Anaconda on a Windows 10 machine which comes with Spyder and Python 3.6 but I wish to upgrade to Python 3.7To create an Anaconda Environment with Python 3.7 is easy by using:conda crea…

Pass in a list of possible routes to Flask?

Im learning Flask and have a question about dynamic routing: is it possible to pass in a list of accepted routes? I noticed the any converter which has potential but had a hard time finding examples o…

Tornado @run_on_executor is blocking

I would like to ask how tornado.concurrent.run_on_executor (later just run_on_executor) works, because I probably do not understand how to run synchronous task to not block the main IOLoop.All the exa…

Using Pandas read_csv() on an open file twice

As I was experimenting with pandas, I noticed some odd behavior of pandas.read_csv and was wondering if someone with more experience could explain what might be causing it.To start, here is my basic cl…

Disable Jedi linting for Python in Visual Studio Code

I have set my linter for Python to Pylint, but I still get error messages from Jedi. I even went to settings.json and added the line "python.linting.jediEnabled": false, but the line, though …

Bar plot with timedelta as bar width

I have a pandas dataframe with a column containing timestamps (start) and another column containing timedeltas (duration) to indicate duration.Im trying to plot a bar chart showing these durations with…

Take screenshot of second monitor with python on OSX

I am trying to make an ambient light system with Python. I have gotten pyscreenshot to save a screenshot correctly, but I cant figure out how to get it to screenshot my second monitor (if this is even …