GraphoViz는 다이어그램 형태의 그림을 생성하기 위한 도구이다.
GraphVis는 내부적으로 dot 이라는 스크립트 언어를 사용한다.
pydot은 파이썬에서 dot 스크립트 언어를 파싱하기 위한 도구이다.
In [1]:
import pydotplus # python3에서는 pydotplus로 해야 됩니다.
In [2]:
import pydot
In [3]:
command = """
digraph G {Hello->World}
"""
In [4]:
graph = pydotplus.graph_from_dot_data(command)
# image = graph.create_png() #아 모르겠다... 패스
In [14]:
image = graph.create_png
In [13]:
from io import StringIO #python3에서는 io로 해야 함
In [9]:
image_buf = StringIO()
In [15]:
image_buf.write(image)
In [16]:
# import StringIO
# image_buf = StringIO.StringIO()
In [17]:
from IPython.core.display import Image
Image(image_buf.getvalue())
Out[17]:
In [18]:
command = """
digraph G {
main -> parse -> execute;
main -> init;
main -> cleanup;
execute -> make_string;
execute -> printf
init -> make_string;
main -> printf;
execute -> compare;
}
"""
In [19]:
# graph = pydot.graph_from_dot_data(command)
graph = pydotplus.graph_from_dot_data(command)
# image = graph.create_png()
image = graph.create_png
In [20]:
image_buf.close()
# image_buf = StringIO.StringIO()
image_buf = StringIO()
image_buf.write(image)
Image(image_buf.getvalue())