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

Explicit color mapping only works for string-type category labels #3033

Closed
timstaley opened this issue Oct 2, 2018 · 3 comments
Closed

Explicit color mapping only works for string-type category labels #3033

timstaley opened this issue Oct 2, 2018 · 3 comments
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@timstaley
Copy link

timstaley commented Oct 2, 2018

Hi folks,
first thing first -really enjoying getting to grips with holoviews - feels like a breath of fresh air after years of matplotlib, so thanks.

Not sure if this is a proper bug or a documentation issue, but in the styling plots examples explicit color-mapping is mentioned and an example given. However, this only works if the entries in the 'color_index' column (and equivalently, keys in the explicit mapping dictionary) are of string type so e.g. the following code:

categorical_points = hv.Points((np.random.rand(100), 
                                np.random.rand(100), 
                                np.random.choice(list(range(4)), 100)), vdims='Category')
explicit_mapping = {0: 'blue', 1: 'red', 2: 'green', 3: 'purple'}
categorical_points.sort('Category').options(color_index='Category', cmap=explicit_mapping, size=5, colorbar=True)

Gives

~/code/external/holoviews/holoviews/plotting/util.py in process_cmap(cmap, ncolors, provider, categorical)
    849     if not isinstance(palette, list):
    850         raise TypeError("cmap argument %s expects a list, Cycle or valid %s colormap or palette."
--> 851                         % (cmap,providers_checked))
    852     if ncolors and len(palette) != ncolors:
    853         return [palette[i%len(palette)] for i in range(ncolors)]

TypeError: cmap argument {0: 'blue', 1: 'red', 2: 'green', 3: 'purple'} expects a list, Cycle or valid matplotlib, bokeh, or colorcet colormap or palette

The use-case for this is that I want to set the 'color_index' to a boolean column then pick specific colors. I want to do so because If, e.g I pick 'tab10' then True/False get mapped to the extreme ends of the categorical colormap and then actually get plotted as quite similar colors - perhaps that's worth filing as a separate issue? I guess the larger issue here is that then normalization needs to handled differently for categorical vs continuous colormaps, so I can see that being a pain.

@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Oct 2, 2018
@philippjfr
Copy link
Member

I'll consider this a bug, basically for integers it currently assumes the data is continuous which means an explicit mapping doesn't make sense but supplying an explicit mapping in itself should be sufficient to declare the color mapping as categorical.

@timstaley
Copy link
Author

So, after a moment's extra thought, I've come up with a basic workaround for my case in the interim:
cmap=bokeh.palettes.Set1[3]
But that does require a little familiarity with Bokeh ;)

@philippjfr
Copy link
Member

Now fixed.

@philippjfr philippjfr added this to the v1.10.8 milestone Oct 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

2 participants