python - PyDot node label with subscript
问题描述
I have the attached code to great a pydot graph and I would like one of the labels to have subscript. I tried the following but it just renders it as Y<SUB>2</SUB>
. How can I obtain it with subscript?
import pydot
graph = pydot.Dot(graph_type='digraph', rankdir="LR")
# add node
graph.add_node(pydot.Node('X', label='X'))
graph.add_node(pydot.Node('Y', label='Y<SUB>2</SUB>'))
# add edege
graph.add_edge(pydot.Edge('X', 'Y'))
graph.write_png("mygraph.png")
解决方案
如果您在您的环境中设置了 LaTex,您可以使用 LaTex 标记为您的图形执行此操作。您必须通过 LaTex 传递结果图,因此需要 dot2tex 工具https://dot2tex.readthedocs.io/en/latest/。
graph.add_node(pydot.Node('Y', label='$Y_{2}$'))
推荐阅读
- sql - SQL Server Always Encrypted - 最大参数数
- javascript - 将所有图像文件从 node.js 发送到前端
- vagrant - 使用打包程序构建 Windows 2012R2 映像:内容类型无效
- spring - 使用 Spring 或 Hibernate 以编程方式创建 DB 表
- python - 如何在 yaml 文件中搜索特定字符串和内容
- angular - 非根模块中的 Angular 6 元素
- docusignapi - Docusign Nuget 包 github
- angular - 在 NgFor (Angular6) 中使用 FormControl 或 ngModel
- amazon-web-services - Athena:在这个比例因子下查询耗尽的资源
- c# - 当连接条件为like时如何在EF中进行JOIN