Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Attempting to make custom discrete color data function:

my custom color:

enter image description here

is it possible to use my custom color

colors = Reverse@Table[Hue@h, {h, 0, 0.7, 1/10}] // N;

Thanks to mfvonh, color function and color data

cf[x_] := 
 Which @@ Flatten[
  MapThread[
  List, {x >= # & /@ Reverse@Most@Range[0, 1, 1/Length@colors],  colors}]]

 colordata=cf /@ Rescale[pts[[All, 2]], {0,0.1}];
share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can just make your own function, though in most situations you can just pass a list of colors.

colors = Table[Hue@h, {h, 0, 0.7, 1/10}];
discrete[x_] := Part[colors, x];
ContourPlot[x + Sin[x^2 + y^2], {x, -4, 4}, {y, -4, 4}, Contours -> 9,
  ContourShading -> colors]

enter image description here

For a gradient, use Blend:

gradient[x_] := Blend[colors, x];
Plot3D[Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, 
 ColorFunction -> (gradient[#3] &)]

enter image description here

share|improve this answer
    
Can you give an example? In Graphics you usually specify colors explicitly with directives. –  mfvonh Jun 18 at 17:28
1  
Here's the basic idea in most Graphics situations: Riffle[Table[Rectangle[{i, 0}], {i, 8}], colors]. (Add //Graphics to see it rendered.) –  mfvonh Jun 18 at 17:33
1  
I'm not sure exactly what you mean, but perhaps this? Graphics3D[{PointSize@.02, First@colors, Riffle[pts, colors]} /. p : {__?NumericQ} -> Point[p]]. –  mfvonh Jun 18 at 21:16
    
That's related to the plotting function. Look at the "Details" section in the ColorFunction docs –  mfvonh Jun 19 at 16:52
1  
Graphics[GraphicsComplex[pts,{Polygon@poly},VertexColors->(gradient/@Rescale[pt‌​s[[All,2]],{0,0.1}])],AspectRatio->1/2,Frame->True] –  mfvonh Jun 19 at 18:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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