如何使用 python 在 graphviz 中使用新的节点形状?
How to use new node shapes in graphviz using python?
我正在使用 python 创建一些 graphviz 图表。默认形状(如图所示)对我来说不够用。我想使用更多的形状。我怎样才能用 python 做到这一点?
一种方法是使用包含您可能想要使用的任何形状的图像:
from graphviz import Digraph
dot = Digraph(comment='The Round Table')
#dot.node('A', label='King Arthur', shape='circle')
dot.node('A', label='King Arthur', color='transparent', image='/path/to/star.png')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')
dot.render('test-output/round-table.gv', view=True)
这将创建以下内容:
我认为这种方法的使用方式存在一些限制,如 the documentation 中所述:
If using SVG (-Tsvg), PostScript (-Tps,-Tps2) or one of the raster formats (-Tgif, -Tpng, or -Tjpg), you can load certain images (e.g., pictures) by file name into nodes.
另一种方法是使用 HTML labels,它允许您使用 <IMG>
属性。
我正在使用 python 创建一些 graphviz 图表。默认形状(如图所示)对我来说不够用。我想使用更多的形状。我怎样才能用 python 做到这一点?
一种方法是使用包含您可能想要使用的任何形状的图像:
from graphviz import Digraph
dot = Digraph(comment='The Round Table')
#dot.node('A', label='King Arthur', shape='circle')
dot.node('A', label='King Arthur', color='transparent', image='/path/to/star.png')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')
dot.render('test-output/round-table.gv', view=True)
这将创建以下内容:
我认为这种方法的使用方式存在一些限制,如 the documentation 中所述:
If using SVG (-Tsvg), PostScript (-Tps,-Tps2) or one of the raster formats (-Tgif, -Tpng, or -Tjpg), you can load certain images (e.g., pictures) by file name into nodes.
另一种方法是使用 HTML labels,它允许您使用 <IMG>
属性。