Plot a decision tree.
The sample counts that are shown are weighted with any sample_weights that might be present.
The visualization is fit automatically to the size of the axis. Use the figsize or dpi arguments of plt.figure to control the size of the rendering.
Read more in the User Guide.
Added in version 0.21.
The decision tree to be plotted.
The maximum depth of the representation. If None, the tree is fully generated.
Names of each of the features. If None, generic names will be used (“x[0]”, “x[1]”, …).
Names of each of the target classes in ascending numerical order. Only relevant for classification and not supported for multi-output. If True, shows a symbolic representation of the class name.
Whether to show informative labels for impurity, etc. Options include ‘all’ to show at every node, ‘root’ to show only at the top root node, or ‘none’ to not show at any node.
When set to True, paint nodes to indicate majority class for classification, extremity of values for regression, or purity of node for multi-output.
When set to True, show the impurity at each node.
When set to True, show the ID number on each node.
When set to True, change the display of ‘values’ and/or ‘samples’ to be proportions and percentages respectively.
When set to True, draw node boxes with rounded corners and use Helvetica fonts instead of Times-Roman.
Number of digits of precision for floating point in the values of impurity, threshold and value attributes of each node.
Axes to plot to. If None, use current axis. Any previous content is cleared.
Size of text font. If None, determined automatically to fit figure.
List containing the artists for the annotation boxes making up the tree.
>>> from sklearn.datasets import load_iris >>> from sklearn import tree
>>> clf = tree.DecisionTreeClassifier(random_state=0) >>> iris = load_iris()
>>> clf = clf.fit(iris.data, iris.target) >>> tree.plot_tree(clf) [...]
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.tree.plot_tree.html