visualise dot files in PyCharm
Asked Answered
M

2

9

I have generated a dot file to visualise a decision tree using the code

import numpy as np
from sklearn.model_selection import train_test_split
import sklearn.tree
from sklearn.datasets import load_breast_cancer

cancer = load_breast_cancer()
X_train, X_test, y_train, y_test =train_test_split(cancer.data,cancer.target, stratify=cancer.target, random_state=42)
tree = sklearn.tree.DecisionTreeClassifier(random_state=0,max_depth=4)
tree.fit(X_train,y_train)
sklearn.tree.export_graphviz(tree,out_file="tree.dot",class_names=cancer.target_names,feature_names=cancer.feature_names,impurity=False, filled=True)

This successfully creates the tree.dot file. I can now generate a png file using the dot.exe utility of graphviz (https://graphviz.gitlab.io/_pages/Download/Download_windows.html)

from subprocess import check_call
check_call(['...PATH_TO_GRAPHVIZ/graphviz-2.38/release/bin/dot.exe','-Tpng','tree.dot','-o','tree.png'])

I would like to visualise the decision tree also within PyCharm. Is there a way to do this?

Menstruate answered 16/9, 2018 at 9:41 Comment(1)
VSCode has a plugin to visualize .dot file. I don't know about pycharm. In fact I am also looking for the same in pycharmMcguinness
H
1

you can install plugin called dotplugin by bzixilu, when you open the dot file, automatically the graph will shown next to it

Heman answered 16/10, 2020 at 0:15 Comment(0)
A
1
sudo apt install graphviz

File > Properties > External Tools

Press +

Fill out as below

Edit tool

dot
-Tpng $FileName$ -o $FileNameWithoutExtension$.png
$FileDir$

To use..

Right click on dot file

External Tools > graphviz-dot-png

A png of the dot file will be generated, you can view this with Pycharm.

Aimless answered 29/4, 2022 at 19:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.