2
$\begingroup$

Following instructions from Is it possible to insert new colour schemes into ColorData?, I was able to create the custom color scheme:

enter image description here

by using the following code:

ColorData[1];
new = {{"play", "", {}}, {"Gradients"}, 1, {0, 1}, {White, White, Red, White, White}, ""};
AppendTo[DataPaclets`ColorDataDump`colorSchemes, new];
AppendTo[DataPaclets`ColorDataDump`colorSchemeNames, new[[1, 1]]];
ColorData["play"]

However, I would need the white portion of the gradient to have reduced opacity (e.g. 0.2) instead of it being solid white, and yet have the red portion fully opaque (i.e., solid red). This transparency of the white portion I need, since I will be later displaying something behind the gradient.

I tried naïvely typing {White, Opacity[0.2]} is the code above, but to no avail.

Any way about this?

$\endgroup$

1 Answer 1

1
$\begingroup$

Specifying the full RGB-4-vectors instead seems to work.

ColorData[1];
new = {{"play", "", {}}, {"Gradients"}, 1, {0, 1}, 
   RGBColor @@@ {{1., 1., 1., 0.2}, {1., 1., 1., 0.2}, {1., 0., 0.,1.}, {1., 1., 1., 0.2}, {1., 1., 1., 0.2}},
   ""
   };
AppendTo[DataPaclets`ColorDataDump`colorSchemes, new];
AppendTo[DataPaclets`ColorDataDump`colorSchemeNames, new[[1, 1]]];
colfun = ColorData["play"]
$\endgroup$
1
  • 1
    $\begingroup$ Put another way: you need to explicitly give colors with alpha channels in your user-defined gradient. $\endgroup$ Apr 9, 2018 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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