3
$\begingroup$

The display forms of ColorDataFunction objects (especially after one clicks on the white + sign on them) indicate that these objects have properties like Name, Class, etc. For example:

ColorData["StarryNightColors"]

Mathematica graphics

ColorData[60]

Mathematica graphics


I'd like to write a function that takes a ColorDataFunction object as an argument. How can this function access the properties of a ColorDataFunction object?


FWIW, expressions like the ones below won't work:

ColorData[60, "ColorFunction", "Properties"]

ColorData[60, "ColorFunction"]["Properties"]
$\endgroup$
  • 2
    $\begingroup$ you can get somewhere inspecting FullForm and then addressing parts, eg ColorData[60, "ColorFunction"][[2]]->"Indexed". Not very satisfactory though. $\endgroup$ – george2079 May 4 '17 at 15:18
  • 1
    $\begingroup$ Related: (76612) $\endgroup$ – Mr.Wizard May 23 '17 at 9:52
6
$\begingroup$

The ColorDataFunction is not atomic,

cdf = ColorData["StarryNightColors"];

AtomQ@cdf
(* False *)

so you have direct access to the arguments. Just replace the head with List and you have the four items listed in the box

List @@ cdf
(* {"StarryNightColors", "Gradients", {0, 1}, Blend["StarryNightColors", #1] &} *)
$\endgroup$
4
$\begingroup$

Strictly speaking, I am only talking about the most important property of ColorDataFunction, because you can use FullForm to get the other properties.

There is some additional information. ColorData[scheme] returns a ColorDataFunction. You can use the returned ColorDataFunction directly.

If you check the definition of ColorDataFunction, you will see only Function f really matters if you don't use illegal parameter as the input of ColorDataFunction/Function f.

enter image description here

In:

ColorData["Gradients"]

ColorData["AlpineColors"]
ColorData["AlpineColors"][x]
ColorData["AlpineColors"][1]

Manipulate[
 ColorData["AlpineColors"][x],
 {x, 0, 1, 0.01}]

Out: enter image description here

$\endgroup$

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.