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.