[Matplotlib-devel] [rfc] a better interchange format for colormaps

Nathaniel Smith njs at pobox.com
Wed Apr 20 23:07:09 EDT 2016

On Wed, Apr 20, 2016 at 7:32 PM, Eric Firing <efiring at hawaii.edu> wrote:
> On 2016/04/20 1:22 PM, Nathaniel Smith wrote:
>> Hi matplotters,
>> We've been working on improving our tool for building custom
>> viridis-like colormaps (e.g. adding support for diverging colormaps),
>> and one of the things that we got frustrated by is how there's no
>> compelling way to save and distribute the resulting colormaps so that
>> people can actually use them. So, I wrote up a little spec to
>> standardize a way of storing and distributing colormaps in JSON, with
>> the hope that we can convince everyone to implement this and stop
>> writing silly little conversion scripts all the time.
>> The v0.1 draft is here:
>>      https://github.com/njsmith/json-cm/blob/master/json-cm-spec.md
>> Any comments? There are always a lot of fiddly details to get right in
>> this kind of thing -- I made a bunch of guesses about what kind of
>> stuff is important and how to represent it, but it can only benefit
>> from review from different perspectives. I would equally love to get
>> nitpicky critiques and high-level queries.
>> Thanks!
>> -n
> Nathaniel,
> I like the idea.
> Minor and tentative suggestion: add a key to specify the number of colors.
> Yes, it can be calculated from the length of the "colors" string, but I have
> a hunch the convenience of having it immediately available (even grep-able)
> would be worth the slight redundancy.

Hmm, I'll have to think about that one. My gut reaction is to be wary
about introducing redundancy because it tends to create
source-of-truth problems -- if the two things disagree, then which is
right? -- and then those tend to create interoperability problems.
But, maybe I'm just missing something... I don't think I've ever
grepped for a colormap on the basis of how many control points it
contained, so I might not be the target audience :-). Can you give any
examples of when you'd use this?

> Although matplotlib's colormap support was originally designed by John
> Hunter around his LinearSegmentedColormap scheme, that method for defining
> and recording a colormap has always been baffling to most people--and the
> end result is a simple lookup table anyway.  Therefore I favor moving to the
> direct specification of the evenly-spaced fine-grained color list (suitable
> for matplotlib's ListedColormap) as in your proposal here.

This might improve the handling of discrete/qualitative colormaps too
-- right now AFAICT matplotlib just doesn't handle these sensibly at
all by default. The way the colorbrewer palettes have historically
been mangled in matplotlib is pretty bad :-/


Though in some sense I suppose one has lost as soon as one is trying
to use the Colormap interface's float -> color semantics for a
discrete map -- the seaborn "palette" concept is in some ways closer
to what we'd want for qualitative colormaps.


Nathaniel J. Smith -- https://vorpus.org

More information about the Matplotlib-devel mailing list