Skip to content

Add black Fancy arrows with white background in plot_tree - #15940

Closed
cmarmo wants to merge 8 commits into
scikit-learn:masterfrom
cmarmo:plotree13971
Closed

cmarmo wants to merge 8 commits into
scikit-learn:masterfrom
cmarmo:plotree13971

Conversation

@cmarmo

@cmarmo cmarmo commented Dec 20, 2019

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #13971.

What does this implement/fix? Explain your changes.

Arrows are displayed in Fancy style so they have white background and black edges. This makes them visible even in dark background. See example below.
tree_white
tree_black

Other comments

I'm not totally happy with the arrow length. But I don't know how to access the dimension of the box.

@cmarmo

cmarmo commented Dec 20, 2019

Copy link
Copy Markdown
Contributor Author

Ok, sorry I wasn't aware that this would change test results too... I'm working on it.

@cmarmo

cmarmo commented Jan 1, 2020

Copy link
Copy Markdown
Contributor Author

@amueller, @thomasjpfan I've been told that you are the specialists on plotting functions. Is my fix acceptable? Also, I don't know how to manage the codecov failing checks. Any hints? Thanks for your help.

@amueller

amueller commented Jan 3, 2020

Copy link
Copy Markdown
Member

I feel like it would be more consistent to change the the color of the lines and arrows instead of changing the style of the arrows.

@cmarmo

cmarmo commented Jan 3, 2020 •

Copy link
Copy Markdown
Contributor Author

@amueller thanks for your answer. I need to find a way to make the arrows visible with any background color. I've tried to change the color with something like color='C0' but this property gave me an error in this other PR: the error message in doc-min-dependencies test is

ValueError: to_rgb: Invalid rgb arg "C0"
could not convert string to float: 'c0'

I don't know which other option will let me change the color in a dynamic way.

@amueller

amueller commented Jan 6, 2020

Copy link
Copy Markdown
Member

Can you give a minimal example with black background?

@cmarmo

cmarmo commented Jan 6, 2020

Copy link
Copy Markdown
Contributor Author
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import plot_tree
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt

X, y = load_iris(return_X_y=True)
tree = DecisionTreeClassifier(criterion='gini')
tree.fit(X, y)
fig, ax = plt.subplots(figsize=(10, 10), facecolor='k')
plot_tree(tree, rotate=True, ax=ax);
plt.show()

will produce this image with master and this image with this PR.

@amueller

amueller commented Jan 6, 2020

Copy link
Copy Markdown
Member

I think a better way to make this work is to make plt.style.use('dark_background') work.

Right now that doesn't work, though, probably because we hard-code the face color:
image

@amueller

amueller commented Jan 6, 2020

Copy link
Copy Markdown
Member

this seems good enough to me? #13971 (comment)

@cmarmo

cmarmo commented Jan 6, 2020

Copy link
Copy Markdown
Contributor Author

Ok, as you prefer: closing this.

@cmarmo cmarmo closed this Jan 6, 2020
@cmarmo
cmarmo deleted the plotree13971 branch January 9, 2020 10:44
@cmarmo
cmarmo restored the plotree13971 branch January 17, 2020 07:45
@cmarmo cmarmo reopened this Jan 17, 2020
@cmarmo

cmarmo commented Jan 17, 2020

Copy link
Copy Markdown
Contributor Author

Hello, I'm reopening, asking for a second review: @amueller has not closed the corresponding issue, neither has @StevenLi-DS. So I'm wondering if this is worthing a second chance.
Sorry core-devs I will now start to ping randomly: @NicolasHug, @thomasjpfan , @glemaitre, @jnothman?
Thanks for any insights!

@NicolasHug

Copy link
Copy Markdown
Member

I agree with @amueller that using a context manager to change the color are good enough. I think we should just close the issue and this PR

@cmarmo

cmarmo commented Jan 17, 2020

Copy link
Copy Markdown
Contributor Author

Understood: @NicolasHug could you please close the issue? Thanks.

@cmarmo cmarmo closed this Jan 17, 2020
@cmarmo
cmarmo deleted the plotree13971 branch January 17, 2020 13:13
@NicolasHug

Copy link
Copy Markdown
Member

Done, thanks @cmarmo for the PR though

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add a background color for the arrows in plots by plot_tree

3 participants