【问题标题】:Right-justify list in graphviz, python在graphviz,python中右对齐列表
【发布时间】:2022-02-05 02:27:03
【问题描述】:

在连接列表中的字符串时,我无法让 graphviz 节点标签正确对齐。 如果我将 '\n' 和 '\r' 附加到任一端,则理由有效,但仍显示列表元素(括号和引号):

label_list = ['car','button','cloth']
label = ['\n' + s + '\r' for s in label_list]

如果我使用 join,右对齐会丢失:

label_list = ['car','button','cloth']
label = ['\n' + s '\r' for s in label_list]
label = ''.join(label)

每个 sroush 评论,删除 '\n' 给出:

(如果不使用连接,则类似于第一个示例)。

我想要的只是:

【问题讨论】:

  • 我能找到的最佳参考:stackoverflow.com/questions/65162650/…
  • 认为 '\r' 也包括一个 '\n'。所以从你的程序中删除 '\n' 看看会发生什么。
  • @sroush 谢谢,我用这个建议更新了问题;仍然没有解决方案。
  • 我假设在后台是 dot file is generated, can't you see what the content of this file is? (from this probably you can draw conclusions like the needed number of backslashes , might be you need \\n`

标签: python graphviz


【解决方案1】:

这是一个仅限 Graphviz(无 Python)的解决方案:

graph j {  
 A [label="car\rbutton\rcloth\rmuch more\r"]  
}

捐赠:

【讨论】:

  • 这类似于我上面的第一条评论。我确实需要一个 python 解决方案。谢谢!
【解决方案2】:

通过将列表转换为字符串并删除每个列表元素(括号、逗号等),我得到了想要的结果。

label_list = ['car','button','cloth']
label = [s + '\r' for s in label_list]
label = str(label)[1:-1].replace(',','').replace("'",'')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-27
    • 2015-10-02
    • 2017-03-07
    • 2011-04-09
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多