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

feature request: high-level unique name for accessing palettes #23

Open
andy-esch opened this issue Oct 6, 2017 · 2 comments
Open

feature request: high-level unique name for accessing palettes #23

andy-esch opened this issue Oct 6, 2017 · 2 comments

Comments

@andy-esch
Copy link
Contributor

Sometimes it can be hard knowing how to traverse palettable to get the palette you need. Unless I'm missing something, there does not seem to be a high level way of accessing palettes without prior knowledge about the structure of palettable. It'd be really handy to have a high-level get method to access a palette without advanced knowledge about how it's nested within palettable.

For instance, some palettes can be accessed like:

palettable.<class>.<module>.<palette_name>

E.g., palettable.colorbrewer.diverging.PRGn_11. This requires more information than just the palette name. Programmatically, it'd be accessed like the following if a user needed a specific palette:

>>> r = dict(cls='colorbrewer', module='diverging', palette='PRGn', n_colors='11')
>>> getattr(getattr(getattr(palettable, r['cls']), r['module']), r['palette'] + '_' + r['n_colors']).hex_colors
['#40004B', '#762A83', '#9970AB', '#C2A5CF', '#E7D4E8', '#F7F7F7', '#D9F0D3', '#A6DBA0', '#5AAE61', '#1B7837', '#00441B']

Others palettes are accessed like:

palettable.<class>.<palette_name>

For example, palettable.matplotlib.Inferno_13, which is much more easily accessible but still requires knowledge that the palette comes from matplotlib, which may or may not be relevant to the user.

It'd be really nice to have a high-level get method (or something like that) to retrieve palettes by a unique name that would return the palette object that you want to retrieve information from.

I can imagine something of the form:

>>> mpl_inf_13 = palettable.get('inferno', 13, reversed=True)
>>> mpl_inf_13.hex_colors
['#40004B', '#762A83', '#9970AB', '#C2A5CF', '#E7D4E8', '#F7F7F7', '#D9F0D3', '#A6DBA0', '#5AAE61', '#1B7837', '#00441B']

The user is only defining what they want, but it adds the additional constraint that no two palettes across the package can have the same name.

@jiffyclub
Copy link
Owner

jiffyclub commented Oct 6, 2017

Thanks for this suggestion! What are your thoughts on how folks would know that 'inferno' was a valid palette name in the first place? Docs?

@m-beau
Copy link

m-beau commented May 26, 2021

Hi, any update on this? There should really be a simple rules_them_all dict-like structure available in palettable, so that the unique colormap name is necessary to access the colormap.

I think that a dictionary structure is desirable, as dot indexing is not convenient when one doesn't want to use a specific colormap of the package but rather make all of them accessible within a function, through the use of a string fed as a parameter.

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

3 participants