6
$\begingroup$

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}]; 
$\endgroup$
0

1 Answer 1

9
$\begingroup$

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

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.