我想为使用 pydot 生成的图中的节点添加多行工具提示。这是我正在做的事情:
node = pydot.Node('abc', style='filled', fillcolor='#CCFF00', fontsize=12)
txt = 'foo' + '\n' + 'test'
node.set_tooltip(txt)
我看到的工具提示显示为“foo\ntest”
我将不胜感激任何帮助。
谢谢 阿比 git
最佳答案
标签和名称似乎支持换行符 ( Newline in node label in dot (graphviz) language ),但工具提示直接放入生成的 HTML 中,不会将“\n”视为特殊字符。
使用直接字符代码是一种替代方法。 (参见 Formatting 和 ASCII Control Codes )
node = pydot.Node('abc', style='filled', fillcolor='#CCFF00', fontsize=12)
# specify HTML Carriage Return (\r) and/or Line Feed (\n) characters directly
txt = 'foo' + ' ' + test'
node.set_tooltip(txt)
或者一些简单的预处理可以让您保留 '\n' 形式:
node.set_tooltip(txt.replace('\n', ' '))
- 请注意,对于 HTML-Like Labels ,使用上面的替换为实体是获得多行工具提示的唯一方法。
关于graphviz - pydot 图的多行工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16671966/