Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download the image created using graphviz

I have used Decision Tree to solve a problem. Then I have used graphviz to obtain the pictorial version of the decision tree.

import graphviz 
dot_data = tree.export_graphviz(clf, out_file=None) 
graph = graphviz.Source(dot_data) 
dot_data = tree.export_graphviz(clf, out_file=None, 
                            feature_names=f_name,   
                            class_names=['Topper', 'Not a topper'],  
                            filled=True, rounded=True,   
                            special_characters=True)  
graph = graphviz.Source(dot_data)
graph 

I wish to download this tree generated in .png, .jpg, or any suitable format. Is it possible?

like image 470
mahmood 16cs187 Avatar asked Oct 27 '25 06:10

mahmood 16cs187


1 Answers

From digraph source create an image

digraph source - 
graph_data = "digraph G { ...... }"

fie_ext = 'png'
temp_img = 'temp_file'
my_graph = graphviz.Source(graph_data)
my_graph.render(temp_img,format=fie_ext, view=False)

render() method auto generate an image with temp_file.png extension in your current directory.

like image 79
Vijay Avatar answered Oct 28 '25 21:10

Vijay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!