gpt4 book ai didi

Python 图表 : Latex Math rendering of node labels

转载 作者:太空宇宙 更新时间:2023-11-03 16:51:10 25 4
gpt4 key购买 nike

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

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')

结果如下图

Figure 1

图1

最佳答案

也许https://dot2tex.readthedocs.org/en/latest/会为你工作吗?尝试一下

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

关于Python 图表 : Latex Math rendering of node labels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35830447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com