MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ColorFunctions again (making z=0 be different from z=1)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50495] Re: [mg50488] ColorFunctions again (making z=0 be different from z=1)
  • From: "Owen, HL (Hywel)" <H.L.Owen at dl.ac.uk>
  • Date: Wed, 8 Sep 2004 05:10:12 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

These functions were culled from previous posts (thanks to those people,
whose names I've forgotten!):

First, you will find a list of colours to be handy:

<< Graphics`Colors`

then this function(s) is very clever:

ColorQ[x_] := MemberQ[{RGBColor, GrayLevel, Hue, CMYKColor}, Head[x]];
GradientColor[x : {cols__?ColorQ}] := GradientColor[Transpose[{Range[0, 
Length[x] - 1]/(Length[x] - 1), x}]];
GradientColor[x : {{_, _?ColorQ} ..}] := Module[{newx = x, res, 
      redf, greenf, xvals, 
        cols, bluef, func}, newx = Sort[x, OrderedQ[{#1[[1]], #2[[1]]}] &];
      If[newx[[1, 1]] =!= 0, PrependTo[newx, {0, newx[[1, 2]]}]];
      If[N[Last[newx][[1]]] =!= 1., AppendTo[newx, {1, Last[newx][[2]]}]];
      {xvals, cols} = Transpose[newx];
      res = Transpose[{xvals, #}] & /@ Transpose[Apply[
      List, ToColor[#, RGBColor] & /@ cols, {1}]];
      {redf, greenf, 
                bluef} = Interpolation[#, InterpolationOrder -> 1] & /@ res;
      func = Evaluate[RGBColor[redf[#], greenf[#], bluef[#]]] &;
      func];

In your plot, use:

ColorFunction -> GradientColor[{Black, Red, Yellow}]

replace the list of colours with whatever set you find most useful. There
was a version of this code that could do a legend, but I took it out as it
makes it hard to combine multiple plots. I'll see if I can find the
original.

Cheers,

Hywel

> -----Original Message-----
> From: AES/newspost [mailto:siegman at stanford.edu]
To: mathgroup at smc.vnet.net
> Sent: 07 September 2004 10:44
> To: mathgroup at smc.vnet.net
> Subject: [mg50495] [mg50488] ColorFunctions again (making z=0 be different from
> z=1)
> 
> 
> The simple  ColorFunction->Hue  option in Plot3D, ContourPlot, and 
> DensityPlot, makes z = 0 appear the same as z = 1 (i.e., both bright 
> red), a situation which seems to me to make these plots confusing 
> and more difficult to interpret, given that "high peaks" and "sea
> level valleys" may be the most interesting features of such a plot.
> 
> Do others have any favorite, not too messy ColorFunctions that
> make values near z = 0 tend toward white, or grey, or less bright,
> or something so that there's a clearly unidirectional visual
> effect going from values of z near 0 to those near z = 1?
> 
> [And as a side question, a simple Prolog or Epilog code to put 
> one of those scaled and labelled vertical color bars alongside a
> ContourPlot or DensityPlot, perhaps with the same vertical
> height as the plot itself?]
> 


  • Prev by Date: Re: ColorFunctions again (making z=0 be different from z=1)
  • Next by Date: Re: plot thousands(?) of trajectories in single graph.
  • Previous by thread: Re: ColorFunctions again (making z=0 be different from z=1)
  • Next by thread: Re: ColorFunctions again (making z=0 be different from z=1)