I'm trying to read a .dot file produced by sklearn.tree.export_to_graphviz into a graph using NetworkX. I plan to add this graph as a subplot in a pyplot graph. While I'm able to use nx.drawing.nx_pydot.read_dot to obtain the graph structure, all of the labels seem to disappear.
This is what I'm trying:
randTree = (nx.drawing.nx_pydot.read_dot("tree_output.dot"))
nx.draw_networkx(randTree)
The .dot file is:
digraph Tree {
node [shape=box] ;
0 [label="X[0] <= 332.72\nsamples = 19\nvalue = -0.41"] ;
1 [label="samples = 11\nvalue = -0.67"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="X[0] <= 576.73\nsamples = 8\nvalue = -0.04"] ;
0 -> 2 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
3 [label="samples = 4\nvalue = -0.05"] ;
2 -> 3 ;
4 [label="samples = 4\nvalue = -0.03"] ;
2 -> 4 ;
}
What results is a graph with 4 circles labeled 1-4, without any other labels or properties (I imagine the box shape is a property of the node so that's why they're all circles), which is linked below. If there is another way to show this decision in a pyplot plot, I'd be happy to hear!