jiffyclub / palettable

Color palettes for Python
https://jiffyclub.github.io/palettable/
Other
768 stars 73 forks source link

Color maps with Alhpa Transparency values #33

Open jboarman opened 4 years ago

jboarman commented 4 years ago

Are there any palettes with alpha transparency values specified? If not, is there a good way to add alpha values to existing palette?

jiffyclub commented 4 years ago

There's nothing built-in with alphas, but I bet we can figure out a way to use that. Are you wanting different alphas with different colors, or a consistent alpha across the palette? Are you using the palette with matplotlib?

jboarman commented 4 years ago

I'm using uniform alpha values. And yes, using matplotlib.

jiffyclub commented 4 years ago

If you can provide a concrete example of what you're trying to do I might be able to give better advice, but as a starting point, I think matplotlib understands colors as (red, green, blue, alpha) where each of those is a floating point number between 0 and 1. So you may be able to use the .mpl_colors property on a palette, which is a list of (red, green, blue) tuples, and add your own alpha to the end of those tuples. If you need a matplotlib colormap object, palettable uses LinearSegmentedColormap.from_list under the hood: https://github.com/jiffyclub/palettable/blob/768d5ef8d14437d4bffa27afb96e4990c919a25d/palettable/palette.py#L88-L101