Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make colors configurable #30

Closed
dhaitz opened this issue Jan 17, 2019 · 12 comments · Fixed by #43
Closed

Make colors configurable #30

dhaitz opened this issue Jan 17, 2019 · 12 comments · Fixed by #43
Labels
enhancement New feature or request

Comments

@dhaitz
Copy link

dhaitz commented Jan 17, 2019

Hi!

Could you make the colors configurable? I like the idea of being colorblind-friendly; unfortunately on some projectors the palette colors are indistinguishable.

Thanks and cheers

@parrt
Copy link
Owner

parrt commented Jan 23, 2019

good idea!

@parrt parrt added the enhancement New feature or request label Jan 23, 2019
@Ashafix
Copy link
Contributor

Ashafix commented Jun 12, 2019

@dhaitz : How should the configuration look like in your opinion? Global or per function call?

As far as I could see from the code, the colors are currently just global constants which can be overwritten, e.g. dtreeviz.trees.GREY = "#ff0000" and you get red labels.

Probably the easiests way would be to have a global dictionary which stores the colors and can be overwritten for customization, e.g. COLORS = {'label': GREY, ', 'title': BLACK}

@parrt : Any preferences?

from sklearn import tree
from sklearn.datasets import load_boston
import dtreeviz.trees

dtreeviz.trees.GREY = "#ff0000"

regr = tree.DecisionTreeRegressor(max_depth=2)
boston = load_boston()
regr.fit(boston.data, boston.target)

viz = dtreeviz.trees.dtreeviz(regr, boston.data, boston.target, target_name='price', feature_names=boston.feature_names)
              
viz.view()

image

@parrt
Copy link
Owner

parrt commented Jun 12, 2019

I think some kind of argument would be better than tweaking the globals.

@dhaitz
Copy link
Author

dhaitz commented Jun 13, 2019

@Ashafix , @parrt : Maybe something like this in dtreeviz/trees.py?

GREY = "#ff0000"
...
COLORS = {'label': GREY, ', 'title': BLACK}

def dtreeviz(..., 
             colors: dict = None
             ):

    if colors is None:  # fall back to module-level default colors
        colors = COLORS

@parrt
Copy link
Owner

parrt commented Jun 13, 2019

or just colors:dict=COLORS?

@dhaitz
Copy link
Author

dhaitz commented Jun 14, 2019

@parrt ah yes, of course this is the simple and straightforward solution.

Another approach would be:

if colors is None:
    colors = dict(COLORS, **colors)

which would allow you to overwrite only certain keys in the colors argument and use the defaults from COLORS for all others.

@Ashafix
Copy link
Contributor

Ashafix commented Jun 14, 2019

Please have a look at Ashafix@ee02d0f
and let me know if it's the right direction.

  • Each function has an optional parameter colors which is a dictionary, each dictionary key can overwrite a default value.
  • The colors are stored in colors.py allowing easy global modification
  • Having a new optional parameter should allow re-use of all previous scripts which use dtreeviz
  • change_colors.py demonstrates the effects with a few examples
  • "tested" on Windows 10 and Ubuntu 16.04

@parrt
Copy link
Owner

parrt commented Jun 14, 2019

@Ashafix Looks pretty good! widespread changes but it's adding a lot of control to the look of the plots. could you make a PR? I'm wondering if colors.py should be a separate file or included... thoughts?

@Ashafix
Copy link
Contributor

Ashafix commented Jun 14, 2019

@parrt : Thanks for the quick feedback! Personal opinion, I'd prefer a separate file for the colors/configuration, but not my library.

I will test and document all parameters and then create a PR.

@parrt
Copy link
Owner

parrt commented Jun 14, 2019

sounds great. does extra file cause any package weirdness for users? if invisible, let's factor out into colors.py :)

@mattharrison
Copy link

While you are on colors, could you do font's as well :) (Ie make them configurable)

@Ashafix
Copy link
Contributor

Ashafix commented Jul 5, 2019

@mattharrison : one PR at a time...

@parrt parrt closed this as completed in #43 Jul 5, 2019
parrt added a commit that referenced this issue Jul 5, 2019
Configurable colors, resolves #30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants