繁体   English   中英

Python Graphs:节点标签的 Latex Math 渲染

[英]Python Graphs: Latex Math rendering of node labels

我正在使用以下代码创建一个pygraphviz图。 但是否有可能让它呈现乳胶数学方程(见图 1)? 如果没有,是否有替代的 python 库可以绘制类似的图形但支持乳胶渲染?

import networkx as nx

from networkx.drawing.nx_agraph import to_agraph

G=nx.DiGraph()
G.add_node(1,color='blue',style='filled',
             fillcolor='white',shape='square', label="$3x+2$")
G.add_node(2)
G.add_node(3)
G.add_edge(1, 2)
G.add_edge(1, 3)
G.add_edge(3, 4)

A = to_agraph(G)
A.layout('dot')
A.draw('test1.png')

这导致下图

图1

图1

也许https://dot2tex.readthedocs.org/en/latest/对你有用? 尝试

import dot2tex
texcode = dot2tex.dot2tex(A.to_string(), format='tikz', crop=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM