4
$\begingroup$

I have this contour plot that has values ranging from ~0.01 to ~100, however, there aren't distinct colors between every order of magnitude. I've tried putting a Log scale on the ColorFunction, scaling my data with a Log, and playing with ColorFunctionScaling, but none of these got me color distinctions between orders of magnitude.

ContourPlot[1/100 E^(x + y), {x, -1, 5}, {y, -1, 5}, 
 Contours -> {.01, .1, 1., 10., 100.}, ContourStyle -> None, 
 ColorFunctionScaling -> True, 
 ColorFunction -> (ColorData["SiennaTones"]), PlotRange -> All, 
 PlotLegends -> True]

<code>ContourPlot</code> output In this plot, every order of magnitude is a different color, but the difference is only very slight between 0.01 and 0.1, and still subtle between 0.1 and 1. I'd like to be able to see all of them distinctly.

$\endgroup$
1
  • $\begingroup$ Could you simply plot Log[f[x,y]] instead of f[x,y]? $\endgroup$ Jul 27, 2019 at 12:21

1 Answer 1

6
$\begingroup$

You can use ContourShading instead of ColorFunction:

contours = {.01, .1, 1., 10., 100.};
colors = ColorData["SiennaTones"] /@ Subdivide[Length @ contours];

ContourPlot[1/100 E^(x + y), {x, -1, 5}, {y, -1, 5}, 
 Contours -> contours, ContourStyle -> None, 
 ContourShading -> colors, 
 PlotRange -> All, PlotLegends -> True]

enter image description here

Alternatively, discretize the ColorFunction argument:

discretize = Total[UnitStep[# - contours]] / Length[contours]&;

ContourPlot[1/100 E^(x + y), {x, -1, 5}, {y, -1, 5}, 
 Contours -> contours, ContourStyle -> None, 
 ColorFunctionScaling -> False, 
 ColorFunction -> (ColorData["SiennaTones"][discretize@#]&), 
 PlotRange -> All, PlotLegends -> True]

enter image description here

An alternative way to discretize the color function argument:

ClearAll[pw]
pw[x_]:= Piecewise[Thread[{Subdivide[Length @ contours],
  BlockMap[#[[1]] <= x < #[[2]] &, Join[{0}, contours, {2 Max @ contours}], 2, 1]}], 1]

ContourPlot[1/100 E^(x + y), {x, -1, 5}, {y, -1, 5}, 
 Contours -> contours, ContourStyle -> None, 
 ColorFunctionScaling -> False, 
 ColorFunction -> (ColorData["SiennaTones"][pw[#]]&), 
 PlotRange -> All, PlotLegends -> True]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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