13
$\begingroup$

Bivariate colormaps, where the color returned is a function of two values not one, are sometimes used in choropleth maps and are also useful for visualising complex functions where we might want to use color for phase information and brightness for amplitude.

Obviously some simple bivariate colormaps are just the product of two independent functions, eg Darker[Hue[x],y], however I have one for which this is not the case.

I have seen the post and excellent answer here and I already have a package I use to add a few normal colormaps into colordata (the viridis, inferno, plasma, and magma schemes from matplotlib). In the post linked above new color schemes are added with a definition such as:

{{"Viridis", "matplotlib viridis", {}}, {"Gradients"}, 1, {0, 1}, viridisColorPoints, ""}

Of this I (think) understand all apart from the single 1. My hope was that turning this into a 2, and maybe fudging some other bits, would create a bivariate map... I have had no success.

So is there anyway / can anyone find anyways, to allow us to build in 2d colorschemes, which we can then access like:

ColorData["bivariateColoring"][0.3,0.4]

Here is the colormap I would like to implement: enter image description here

EDIT: The Lightness axis is incorrectly labelled going from 0 to 1 instead of 1 to 0!

$\endgroup$
  • 4
    $\begingroup$ I think you are on the right track - the 1 is the value returned by the "ParameterCount" property. The inclusion of that property seems to imply that multi-parameter colormaps may one day be possible, but AFAICS the code in DataPaclets`ColorDataDump is not yet set up to deal with more than one parameter. Every built-in colormap has a ParameterCount of 1. $\endgroup$ – Simon Woods Nov 23 '16 at 12:29
4
+50
$\begingroup$

If you take a cropped image of your target colormap (the variable r below), you could just interpolate it:

c = ImageData@r;
xs = Range[0, 1, 1/(Dimensions[c][[1]] - 1)] // N;
ys = Range[0, 1, 1/(Dimensions[c][[2]] - 1)] // N;
t = Table[{xs[[i]], ys[[j]], c[[i, j]]}, {i, 418}, {j, 439}];

$interp = Interpolation[Flatten[t, 1]];

cf[x_, y_] := Quiet[RGBColor @@ (Ramp /@ $interp[x, y])]

enter image description here

Grid@Table[cf[i, j], {i, 0, 1, .1}, {j, 0, 1, .1}]

enter image description here

Unfortunately, evaluating interpolation function objects is super slow.

$\endgroup$
  • $\begingroup$ An issue with this approach is that it is not guaranteed that your interpolation function will remain between 0 and 1, i.e. to have a well defined color. To ensure that, you might for example have to add InterpolationOrder -> 1 in Interpolation, as linear interpolations always remain between the interpolated values. (In addition, the Ramp function is unknown in my MMA?) $\endgroup$ – jibe Nov 28 '16 at 18:39
  • $\begingroup$ @jibe Ramp is in v11 $\endgroup$ – M.R. Nov 28 '16 at 19:43
  • $\begingroup$ Thanks for the input. I actually have the colormap - I generate it programatically in MMA. My desire was (is) to insert it into ColorData as is currently possible with univariate colormaps. As @Simon Woods hints at, it may not be possible yet... :( $\endgroup$ – Quantum_Oli Dec 9 '16 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.