关于python:Webgraphviz输出不会围绕决策树页面

Webgraphviz output does not wrap around the page for decision tree

我需要生成的完整树的图像,但它不会环绕,没有下载或保存图像选项。
剩下的唯一选择是截取不捕获整个树的屏幕截图。

我如何得到整棵树?

我已经在Spyder中使用此方法生成了一棵树

1
2
3
4
5
6
7
#Displaying the decision tree
from sklearn import tree
#from StringIO import StringIO
from io import StringIO
#from StringIO import StringIO
with open("classifier.txt","w") as f:
 f = tree.export_graphviz(classifier, out_file=f)

这将生成一个文件classifer.txt,将其复制并粘贴到http://webgraphviz.com/后会生成一个决策树。

这是输出的图像

快照已缩小到最大程度。


好的,我已经通过广泛的谷歌搜索来解决该问题,现在可以将其另存为png。

显示决策树

1
2
3
4
5
6
7
8
9
10
11
12
13
graph=pydotplus.graph_from_dot_data(out.getvalue())

"’ # Display inline image of Tree - Inline image is not useful

Img=(Image(graph.create_png()))

display(Img)

"


#Write image to file so it can be rotated and expanded

graph.write_png('Your_File_Name.png’)