Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Spectra – Python color scales made easy (github.com/jsvine)
33 points by jsvine on March 23, 2015 | hide | past | favorite | 13 comments



Looks like a very useful little library. Although, have you looked at OpenColourIO and its Python bindings? It is the VFX industry standard for working with colour spaces, most companies will use OCIO for colour management throughout the process.


I hadn't heard of OpenColourIO; it looks fascinating and quite powerful. Thanks for the tip!


This looks really useful. I've played around with colormaps in a few visualization projects, but I've never made the time to learn about the various color packages.

What does this add to colormath and grapefruit?


Thanks! Colormath does an amazing job handling the mathematical conversions between color spaces, but has (at least to me) a somewhat verbose API. Spectra wraps that API in something simpler, and adds scales, ranges, blending, brightening/darkening, and saturation/desaturation.

Spectra uses grapefruit for parsing HTML names and hexcodes.


I'm most excited about the color scales. It looks like a helpful tool for situations where the standard colormaps in matplotlib/pyplot don't work well. Is that an appropriate use case?

I also like seeing nbviewer used for documentation, I haven't seen that very often.


> It looks like a helpful tool for situations where the standard colormaps in matplotlib/pyplot don't work well. Is that an appropriate use case?

Yes, that's definitely the type of use-case I had in mind. Another big one: Choropleth maps.

> I also like seeing nbviewer used for documentation, I haven't seen that very often.

Glad to hear it! It's my first attempt at writing documentation in an IPython notebook. Seemed like a good fit for something so visual.


Unrelated to the library itself: I dislike when python projects have an external website containing the docs, and have no docstrings in the code itself. Not only is the code harder to read, but it makes the inbuilt help() useless.


Fair criticism. I should add those docstrings. Issue opened: https://github.com/jsvine/spectra/issues/1


Added docstrings in v0.0.6: https://github.com/jsvine/spectra/issues/1


Doesn't seem terribly well specified. Is the rgb space actually sRGB? And what is the parameter to brighten/darken/saturate/desaturate?


Yes, the library definitely does need some stronger specs. Thanks for flagging. Addressing these two specific issues:

> Is the rgb space actually sRGB?

Yes. Added: https://github.com/jsvine/spectra/commit/7f1ac6f5287340ed356...

> And what is the parameter to brighten/darken/saturate/desaturate?

The parameter for brighten/darken is a positive/negative linear adjustment to the L(ightness) value of the color's Lab representation. (Spectra converts the color to Lab, makes the change, and then converts back to the original color space.)

Likewise, the parameter for saturate/desaturate is a positive/negative linear adjustment to the c(hroma) value of the color's Lch representation.

Added a note here: https://github.com/jsvine/spectra/commit/fd3cbde9338ce388849...

The goal is to, ultimately, have all these details in the docstrings: https://github.com/jsvine/spectra/issues/1


What happens when the adjusted color goes out of gamut?


Another thanks for flagging, mark-r. I've updated spectra to address this issue more explicitly. Per colormath[0], colors are allowed to go out of gamut. Colors now have `mycolor.rgb` and `mycolor.rgb_clamped` properties; `mycolor.hexcode` uses the clamped values. Are there other ways you'd like to see the out-of-gamut issue addressed? Open to suggestions.

[0]: http://python-colormath.readthedocs.org/en/latest/conversion...




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: