![](/img/trans.png)
[英]Python Plotting Data Using the Row referring to rows to columns from CSV file
[英]Plotting the Digraph with graphviz in python from DOT file
我能夠使用Source
類來解決它。
from graphviz import Source
temp = """
digraph G{
edge [dir=forward]
node [shape=plaintext]
0 [label="0 (None)"]
0 -> 5 [label="root"]
1 [label="1 (Hello)"]
2 [label="2 (how)"]
2 -> 1 [label="advmod"]
3 [label="3 (are)"]
4 [label="4 (you)"]
5 [label="5 (doing)"]
5 -> 3 [label="aux"]
5 -> 2 [label="advmod"]
5 -> 4 [label="nsubj"]
}
"""
s = Source(temp, filename="test.gv", format="png")
s.view()
輸出將在同一文件夾中,並且可以更改格式。
PS - 在 Ubuntu 上安裝graphviz
。 首先使用sudo apt install graphviz
進行sudo apt install graphviz
,然后使用sudo pip install graphviz
,否則將無法工作。
您可以使用API 中定義的Source.from_file('/path/to/dot_file')
函數。
因此代碼將是:
from graphviz import Source
path = '/path/to/dot_file'
s = Source.from_file(path)
s.view()
我在 Python 中使用點文件顯示了一個非常短的代碼。
代碼是這樣的:
from graphviz import Source
path = 'abcd.dot'
s = Source.from_file(path)
print(s.source)
s.render('abcd.gv', format='jpg',view=True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.