Skip to content

ENH use colors from style in tree plotting#17187

Merged
jnothman merged 3 commits intoscikit-learn:masterfrom
amueller:plot_tree_styles
May 21, 2020
Merged

ENH use colors from style in tree plotting#17187
jnothman merged 3 commits intoscikit-learn:masterfrom
amueller:plot_tree_styles

Conversation

@amueller
Copy link
Copy Markdown
Member

@amueller amueller commented May 11, 2020

fixes #16943 and some more of #13971.
This doesn't change the edge color for the bounding boxes, but it adjusts the background color of the boxes and the arrow colors.

import matplotlib.pyplot as plt
import seaborn as sns
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);

as before:
image

with plt.style.use('dark_background'):
before:
image

this pr:
image

with sns.set_style('whitegrid'):
before:
image

this pr:
image

with sns.set_style('dark'):
before:
image

this pr:
image

@amueller
Copy link
Copy Markdown
Member Author

I also did

for style in plt.style.available:
    with plt.style.context(style):
        plt.figure()
        tree.plot_tree(clf)

and all of them look reasonable. I didn't test all the seaborn styles but I think they should be fine.

No idea if this should be tested.
If this looks ok I can add a whatsnew.

@cmarmo
Copy link
Copy Markdown
Contributor

cmarmo commented May 12, 2020

If this looks ok I can add a whatsnew.

For what it matters, this looks good to me. Thanks! :)

Copy link
Copy Markdown
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a big enough fix to be added to the 0.24 whats new.

LGTM

@jnothman jnothman changed the title use colors from style in tree plotting ENH use colors from style in tree plotting May 21, 2020
@jnothman jnothman merged commit 2f26540 into scikit-learn:master May 21, 2020
@jnothman
Copy link
Copy Markdown
Member

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tree.plot_tree() does not visualize properly if also using seaborn.set_style()

4 participants