我正在尝试使用图形工具在python中创建一个交互式有限状态自动机,但我无法获得边缘标签。
这是python文件:
from graph_tool.all import *
g = Graph()
edge_labels = g.new_edge_property("string")
a = g.add_vertex()
b = g.add_vertex()
e = g.add_edge(a, b)
edge_labels[e] = 'a'
props = {'text': edge_labels}
graph_draw(
g,
eprops=props,
output_size=(200, 200),
)
崩溃:
*** Error in `/usr/lib/python-exec/python2.7/python2': free(): invalid size: 0x00000000023d0840 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x77a4b)[0x7f73bac77a4b]
/lib64/libc.so.6(+0x7f6be)[0x7f73bac7f6be]
/lib64/libc.so.6(+0x7ffa6)[0x7f73bac7ffa6]
/usr/lib64/python2.7/site-packages/graph_tool/draw/libgraph_tool_draw.so(+0xbba31)[0x7f73970d5a31]
/usr/lib64/python2.7/site-packages/graph_tool/topology/libgraph_tool_topology.so(_ZN5boost11coroutines26detail14pull_coroutineINS_6python3api6objectEE13control_block7destroyEPS7_+0x87)[0x7f73a281daf7]
/usr/lib64/python2.7/site-packages/graph_tool/draw/libgraph_tool_draw.so(_Z10cairo_drawRN10graph_tool14GraphInterfaceEN5boost3anyES3_S3_bNS2_6python4dictES5_S5_S5_dlNS4_3api6objectE+0x548)[0x7f73970d8168]
/usr/lib64/python2.7/site-packages/graph_tool/draw/libgraph_tool_draw.so(+0x251666)[0x7f739726b666]
/usr/lib64/python2.7/site-packages/graph_tool/draw/libgraph_tool_draw.so(+0x251ba8)[0x7f739726bba8]
/usr/lib64/libboost_python-2.7.so.1.65.0(_ZNK5boost6python7objects8function4callEP7_objectS4_+0x2d7)[0x7f73a8aedd67]
/usr/lib64/libboost_python-2.7.so.1.65.0(+0x25f48)[0x7f73a8aedf48]
/usr/lib64/libboost_python-2.7.so.1.65.0(_ZNK5boost6python6detail17exception_handlerclERKNS_9function0IvEE+0x6b)[0x7f73a8af4beb]
/usr/lib64/python2.7/site-packages/graph_tool/libgraph_tool_core.so(+0xa17cb3)[0x7f73a9982cb3]
/usr/lib64/libboost_python-2.7.so.1.65.0(_ZNK5boost6python6detail17exception_handlerclERKNS_9function0IvEE+0x3a)[0x7f73a8af4bba]
/usr/lib64/python2.7/site-packages/graph_tool/libgraph_tool_core.so(+0xa17bd3)[0x7f73a9982bd3]
/usr/lib64/libboost_python-2.7.so.1.65.0(_ZNK5boost6python6detail17exception_handlerclERKNS_9function0IvEE+0x3a)[0x7f73a8af4bba]
/usr/lib64/python2.7/site-packages/graph_tool/libgraph_tool_core.so(+0xa17b73)[0x7f73a9982b73]
/usr/lib64/libboost_python-2.7.so.1.65.0(_ZN5boost6python21handle_exception_implENS_9function0IvEE+0x3f)[0x7f73a8af498f]
/usr/lib64/libboost_python-2.7.so.1.65.0(+0x23059)[0x7f73a8aeb059]
/usr/lib64/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f73bb21cf73]
/usr/lib64/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5595)[0x7f73bb2b6275]
...
/lib64/libc.so.6(__libc_start_main+0xf1)[0x7f73bac20521]
/usr/lib/python-exec/python2.7/python2(_start+0x2a)[0x40064a]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:03 28461541 /usr/bin/python2.7
00600000-00601000 r--p 00000000 08:03 28461541 /usr/bin/python2.7
00601000-00602000 rw-p 00001000 08:03 28461541 /usr/bin/python2.7
00aa9000-027cb000 rw-p 00000000 00:00 0 [heap]
7f737c000000-7f737c022000 rw-p 00000000 00:00 0
7f737c022000-7f7380000000 ---p 00000000 00:00 0
7f7380000000-7f7380021000 rw-p 00000000 00:00 0
7f7380021000-7f7384000000 ---p 00000000 00:00 0
7f7384000000-7f7384021000 rw-p 00000000 00:00 0
7f7384021000-7f7388000000 ---p 00000000 00:00 0
7f738a3be000-7f738a477000 r--p 00000000 08:03 24020070 /usr/share/fonts/dejavu/DejaVuSans.ttf
7f738a477000-7f738a482000 r--s 00000000 08:03 19015130 /var/cache/fontconfig/acc285bc1956c3c4bc7afb41d537a85a-le64.cache-7
...
我不知道从哪里开始寻找这个问题。使用python 3运行会产生类似的错误。如果我删除边缘标签,它就可以工作。
如果不是这个问题的解决方案,是否有任何库可以被建议作为图形工具的替代品?我希望可视化是交互式的,因为我最终希望FSA可以在GUI中修改。
答案 0 :(得分:1)
这是一个cairo / pango错误。
您可以通过明确指定字体系列来解决它:
graph_draw(g, eprops=props, edge_font_family="Times")
编辑:事实上,当使用cairo和boost :: coroutines时,这是一个微妙的错误。现在已在版本2.25中修复此问题,原始示例应该无需修改即可使用。