Cur*_*ous 6 python latex networkx pygraphviz
我正在使用以下代码来创建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')
Run Code Online (Sandbox Code Playgroud)
这导致下图
图1
也许https://dot2tex.readthedocs.org/en/latest/适合您?尝试
import dot2tex
texcode = dot2tex.dot2tex(A.to_string(), format='tikz', crop=True)
Run Code Online (Sandbox Code Playgroud)