处理有向图上的现有标签 object

Manipulate existing labels on a digraph object

从库中生成了这个 graphviz 有向图 object。
我正在尝试更改标签的字体...

digraph "something" {
    graph [rankdir=LR]
    node [margin=0 shape=plaintext]
    "something" [label="something" fontsize=30]
    "other-bwd-other" [label=iglo fontsize=30]
    "other-bwd-other-this" [label="this" fontsize=23]
    [...]

通话中

g.attr('graph', fontname='Arial')
g.attr('node', fontname='Arial')

之后没有效果,我猜是因为那些属性已经存在或者需要在添加节点之前设置?

有没有办法操纵某些节点?
正则表达式会很好,但我似乎不知道如何覆盖节点内容..
或者在遍历 body?

时重建图表

如果有人对超级 hacky 正则表达式“解决方案”感兴趣,
这样就可以了,直到发现官方优雅的解决方案。

gg = graphviz.Digraph(name=most_common_word.lower(), format='png')
gg.attr('graph', rankdir='LR')
gg.attr('node', shape='plaintext', margin='0')

current_dir = os.path.dirname(os.path.realpath(__file__))

for item in generated_graph:
    node_matches = re.findall('\"(.*)\" \[(.*)\]', item.strip())
    edge_matches = re.findall('"(.*)" -> "(.*)"', item.strip())
    if node_matches:
        font_size = re.findall('[0-9]+', node_matches[0][1])
        label = re.findall('label=([a-z]+)', node_matches[0][1])
        if not label:
            label = re.findall('label=\"(.*)\"', node_matches[0][1])
        gg.node(node_matches[0][0], label=label[0], fontsize=font_size[0], fontname=f'{current_dir}/assets/source-sans-pro.ttf')
    if edge_matches:
        gg.edge(edge_matches[0][0], edge_matches[0][1])

gg.render() # gg indeed