# How to assign special colors to the output of DensityPlot?

GROUPS:
 Qasem Marzei 2 Votes I have created the following function for plottingplotDynamical[iterMethod_, points_] := DensityPlot[  iterAlgorithm, {t, xxMin, xxMax}, {s, yyMin,yyMax},   PlotRange -> {1,4}, ColorFunction -> {Orange, Blue, Black, Green},   PlotPoints -> points]The possible results of " iterAlgorithm " are 1 , 2, 3 or 4. I would like to assigning colours to numbers like so: Orange to 1,Blue to 2,Black to 3 and Green to 4. How can I do this?And complete Algorithm is:  F = Compile[{{t, _Real}, {s, _Real}}, {t^2 + s^2 - 4, -Exp[t] + s -       1}]; dF = Compile[{{t, _Real}, {s, _Real}}, {{2 t, 2 s}, {-E^t, 1}}]; invdF = Compile[{{t, _Real}, {s, _Real}}, {{1/(      2 E^t s + 2 t), -((2 s)/(2 E^t s + 2 t))}, {E^t/(      2 E^t s + 2 t), (2 t)/(2 E^t s + 2 t)}}];  rootF[1] = {-1.59832066552612835, 1.202235854627582} ;rootF[2] = {0, 2} ;rootPosition = Compile[{{t, _Real}, {s, _Real}},   Which[Norm[{t, s} - rootF[1]] < 10.0^(-10), 3,   Norm[{t, s} - rootF[2]] < 10.0^(-10), 2, True,    1], {{rootF[_, _], _Real, _Real}}];iterPsM10 = Compile[{{t, _Real}, {s, _Real}},  Block[{v = F[t, s], w = dF[t, s], u = invdF[t, s], x, y, z, dFz, Q,     uu, vv, Fu, vu, invdFvu},   x = {t, s};   y = x - (1/2 ) u.v;   z = 1/3 (4 y - x);   dFz = dF @@ ({z[[1]], z[[2]]});   Q = Inverse[w - 3 dFz];   uu = y + Q.v;   Fu = F @@ ({uu[[1]], uu[[2]]});   vv = uu + 2 Q.Fu;   vu = 1/2 (vv + uu);   invdFvu = invdF @@ ({vu[[1]], vu[[2]]});   uu - invdFvu.Fu]];iterAlgorithm[iterMethod_, lim_] := Block[{ct, r}, ct = 0; r = rootPosition[t, s];  While[(r == 1) && (ct < lim), ++ct; {t, s} = iterMethod[t, s];    r = rootPosition[t, s]];  If[Head[r] == Which, r = 0];(*"Which" unevaluated*)Return[r]];limIterations = 1000;xxMin = -5; xxMax = 5; yyMin = -5; yyMax = 5;plotDynamical[iterMethod_, points_] := DensityPlot[iterAlgorithm[iterMethod, limIterations],  {t, xxMin, xxMax}, {s, yyMin, yyMax}, PlotRange -> {0, 3},   ColorFunction -> {Green, Black, Orange, Blue},  PlotPoints -> points,   Epilog -> {White, PointSize[.02], Point[rootF[1]], Point[rootF[2]]}];plotDynamical[iterPsM10, 56] Attachments:
Answer
1 year ago
5 Replies
 How to assign special colors to the output of DensityPlot?
Answer
1 year ago
 Dear Qasem,Try using ArrayPlot: ArrayPlot[{{1, 0, 0, 0.3}, {1, 1, 0, 0.3}, {1, 0, 1, 0.7}}, ColorRules -> {1 -> Pink, 0 -> Yellow}] Here you can assign certain values to certain colors.
Answer
1 year ago
 DensityPlot like all graphics take option ColorFunction, which could be a pretty arbitrary function: DensityPlot[y + Sin[x^2 + 3 y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> (RGBColor[1 - #, #, 1] &)] You can make up the function you need.
Answer
1 year ago
 How to assign special colors to the output of DensityPlot?
Answer
1 year ago
 Can anyone help me ?
Answer
11 months ago