4
$\begingroup$

please excuse my bad English, I'm not a native speaker.

This should be fairly simple: Is there a simple way to "reverse" ColorFunction or ColorData?

Let me explain what I mean. Let's say, we have the following plot:

Plot[x, {x, 1, 10}, ColorFunction -> "Rainbow"]

enter image description here

As you can see, the upper part of the plot is colored red, the lower part is colored blue/purple. How do I reverse that? So that the upper part is purple, the lower part red.

Thank you for your help. I appreciate it.


If you're curious why I ask that: I have made this plot showing the number of molecules of three biological substances over time when metabolized by the body.

Image of two plots

$\endgroup$
3
$\begingroup$

To reverse the colours you could try 1-# instead of just # in a pure function passed to ColorFunction. To change how the line segments are coloured, include an exponent as follows.

Manipulate[
   Plot[E^{-x, -1.2 x, -2.4 x}, {x, 0, 5},
      ColorFunction -> (ColorData["Rainbow", (1 - #)^e] &),
      PlotRange -> {{0, 5}, {0, 1}}, Frame -> True, ImageSize -> 450,
      FrameLabel -> {"Zeit in Minuten", "Anzahl der Wirkstoffmoleküle"}],
   {{e, 1.0, "Exponent"}, 0, 10, Appearance -> "Labeled"}]

exponential decay

$\endgroup$
3
$\begingroup$

This may be a shorter solution.

Plot[x, {x, 1, 10}, ColorFunction -> ColorData[{"Rainbow", "Reverse"}]]

enter image description here

$\endgroup$
1
$\begingroup$

I have found one possible solution… :)

Plot[x, {x, 1, 10}, ColorFunction -> Function[{x, y}, Reverse@ColorData["Rainbow"][y]]]

Is there a better way?

$\endgroup$

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