# RegionFunction generalized to plot a different colour/style for the largest expression [duplicate]

I have several functions of two variables defined in some region, say

functions[x_,y_]:={0,x-y,Sin[x^2-y]}


I'd like a plot to show at a glance the regions where each function is largest, with a different colour or similar. One approach is to just do a RegionPlot for every function, showing where it's biggest, and stick them all together, something like this (apologies for the hideous colours):

Show@Array[RegionPlot[{#} == Ordering[functions[x, y], -1], {x,0,1}, {y,0,1},
MaxRecursion -> 10, PlotStyle -> ColorData[1, "ColorList"][[#]]] &, 3] This is fine as far as it goes, but I can't help but feel there's a better way. For example, if my functions are more expensive to evaluate, and if there are many of them, this is slow, since everything must be done many times.

For two functions, ContourPlot on the difference seems exceedingly sensible, but I can't think of how to generalize it to more than two.

So: what other clever ways might you suggest to implement this?

functions[x_, y_] := {.3, x Sin@y, y Sin@x}
f[x_, y_] := First@Ordering[functions[x, y] // N, -1]
ContourPlot[f[x, y], {x, 0, 1}, {y, 0, 1}, PlotPoints -> 30] Modifying several alternatives suggested in a closely related Q/A: Plot the plane so that ...

flist = {.3, x Sin@y, y Sin@x};


Plot3D viewed from above:

p3d = Plot3D[flist, {x, 0, 1}, {y, 0, 1},
PlotStyle -> ColorData[1, "ColorList"][[;; 3]],
Mesh -> None, ViewPoint -> {0, 0, ∞}, Boxed -> False,
Axes -> False, Lighting -> "Neutral", PlotRangePadding -> 0,
ImagePadding -> 25, ImageMargins -> 0];
frame2d = Plot[x, {x, 0, 1}, Frame -> True, PlotStyle -> None,
ImageMargins -> 0, Axes -> False];
Overlay[{p3d, frame2d}, Alignment -> Center] ContourPlot:

pieceW = Piecewise[Table[{1. i, flist[[i]] == Max[flist]}, {i, 1, Length@flist}]];
ContourPlot[pieceW, {x, 0, 1}, {y, 0, 1}, PlotPoints -> 100,
ImageSize -> 400, Contours -> Range,
ContourStyle -> ColorData[1, "ColorList"][[;; 3]], Exclusions -> None] DensityPlot:

DensityPlot[pieceW, {x, 0, 1}, {y, 0, 1}, PlotPoints -> 100,
ImageSize -> 400, ColorFunction -> (ColorData[1, "ColorList"][[#]] &),
Exclusions -> None, ColorFunctionScaling -> False, ImagePadding -> 25] RegionPlot:

regions = And @@@ (Outer[GreaterEqual, flist, flist] /.  x_ >= x_ :> Sequence[]);
RegionPlot[regions, {x, 0, 1}, {y, 0, 1}, ImageSize -> 400,
PlotPoints -> 100,  PlotStyle -> ColorData[1, "ColorList"], ImagePadding -> 25] • Is this question "closely related" or an actual duplicate of the one you linked to? It certainly looks like a duplicate to me, but I haven't voted to close yet in case I'm missing something. – user484 Nov 20 '14 at 9:05
• Are the questions different? "I have several functions of two variables defined in some region ... I'd like a plot to show at a glance the regions where each function is largest, with a different colour or similar" perfectly describes the other question (except for "smallest" vs. "largest"). – user484 Nov 20 '14 at 9:20
• I do kind of want to hear that aside, but I'll understand if you're not inclined to typing it all up! – user484 Nov 20 '14 at 9:40