Python Graphs:节点标签的Latex Math渲染 [英] Python Graphs: Latex Math rendering of node labels

查看:145
本文介绍了Python Graphs:节点标签的Latex Math渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the following code to create a pygraphviz graph. But is it possible to make it render latex math equations (see Figure 1)? If not, is there an alternative python library that plots similar graphs but supports latex rendering ?

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

推荐答案

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

Maybe https://dot2tex.readthedocs.org/en/latest/ will work for you? Try

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

这篇关于Python Graphs:节点标签的Latex Math渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆