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')
This results in the following figure
Figure 1
Maybe https://dot2tex.readthedocs.org/en/latest/ will work for you? Try
import dot2tex
texcode = dot2tex.dot2tex(A.to_string(), format='tikz', crop=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With