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

Allow definition of color palettes using RGB-tuples #930

Closed
mrksr opened this issue Oct 13, 2016 · 5 comments
Closed

Allow definition of color palettes using RGB-tuples #930

mrksr opened this issue Oct 13, 2016 · 5 comments
Labels
type: feature A major new feature

Comments

@mrksr
Copy link
Contributor

mrksr commented Oct 13, 2016

Seaborn offers an API to create new color palettes on the fly. These APIs return lists of RGB-Tuples:

In[1]: sns.color_palette()
Out[1]: 
[(0.2980392156862745, 0.4470588235294118, 0.6901960784313725),
 (0.3333333333333333, 0.6588235294117647, 0.40784313725490196),
 (0.7686274509803922, 0.3058823529411765, 0.3215686274509804),
 (0.5058823529411764, 0.4470588235294118, 0.6980392156862745),
 (0.8, 0.7254901960784313, 0.4549019607843137),
 (0.39215686274509803, 0.7098039215686275, 0.803921568627451)]

It would be very nice to be able to use them in Holoviews directly:

%%opts Curve (color=hv.Cycle(values=sns.color_palette()))

hv.Overlay([curve1, curve2, curve3])

However, Cycle (and Palette) assume colors to be defined as hex strings (like #FF0000) or names (like green).
It is possible to convert the seaborn palette like so:

hv.Cycle(values=[hv.plotting.bokeh.util.rgb2hex(c) for c in sns.color_palette()])

But this is quite cumbersome. Ideally, Holoviews would just accept RGB tuples anywhere it accepts hex strings.

@philippjfr philippjfr added the type: feature A major new feature label Oct 24, 2016
@philippjfr
Copy link
Member

philippjfr commented Oct 24, 2016

@mrksr I just tried it and it seems to work fine for me even without converting to hex. I did find that declaring the Cycle directly in the output magic doesn't work, e.g.:

%%opts Curve (color=hv.Cycle(values=sns.color_palette('Set1')))

Seems to throw an error, but if you declare it separately:

cycle = hv.Cycle(values=sns.color_palette('Set1'))

%%opts Curve (color=cycle)
hv.Overlay([hv.Curve(np.arange(10)*i) for i in range(3)])

It seems to work fine in both matplotlib and bokeh. Could you confirm?

@philippjfr
Copy link
Member

I've got a fix for the parser so that %%opts Curve (color=hv.Cycle(values=sns.color_palette('Set1'))) just works. Will make a PR later today.

@mrksr
Copy link
Contributor Author

mrksr commented Oct 25, 2016

Indeed, defining the cycle separately seems to work fine. Thank you for the fix!

@philippjfr
Copy link
Member

Once the parser fixes referenced above are merged you'll be able to define it inline in the magic as well. I'll close this issue now though.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature A major new feature
Projects
None yet
Development

No branches or pull requests

2 participants