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

Add simple make_palette interface #17

Open
olgabot opened this issue Jul 4, 2017 · 1 comment
Open

Add simple make_palette interface #17

olgabot opened this issue Jul 4, 2017 · 1 comment

Comments

@olgabot
Copy link

olgabot commented Jul 4, 2017

Right now, there's a barrier for me to use palettable directly because I have to remember to include the number of colors I want for each colormap when I do the import, and I don't always know where I want to look for the palette I want. Could there be a palettable.make_palette("palettename", n_colors=8) - type interface?

@jiffyclub
Copy link
Owner

Hi, thanks for the suggestion! This kind of exists because almost every module has a get_map function (not called get_palette for historical reasons), but the API varies per-module and it's not documented. For example:

In [6]: palettable.wesanderson.get_map('Zissou')
Out[6]: <palettable.wesanderson.wesanderson.WesAndersonMap at 0x103222b38>

In [8]: palettable.colorbrewer.get_map('Blues', 'sequential', 5)
Out[8]: <palettable.colorbrewer.colorbrewer.BrewerMap at 0x109d034a8>

In [12]: palettable.cmocean.sequential.get_map('Turbid_200')
Out[12]: <palettable.cmocean.cmoceanpalette.CmoceanMap at 0x109d27358>

In [13]: palettable.matplotlib.get_map('Viridis_20')
Out[13]: <palettable.matplotlib.matplotlib.MatplotlibMap at 0x109d30128>

(And cubehelix has its own special thing in addition to get_map: http://jiffyclub.github.io/palettable/cubehelix/#make)

One of the challenges with implementing this more generally is that not every palette supports an arbitrary number of colors (really none of them do, but some do up to an upper limit). In particular, qualitative palettes are available for whatever colors are defined and no more. All the colorbrewer palettes max out at 10-12 defined colors, though sequential and diverging ones would probably support interpolation.

All that said, I think is technically possible but it'd require a lot of runtime validation and its usability would hinge on giving the user useful feedback when they ask for something that's not possible to provide. With that in mind, improving discoverability in some other way might be a better use of time. Maybe improvements to the docs or standardizing the get_map function?

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

No branches or pull requests

2 participants