# Logarithmic scale in the legend of a ListContourPlot

Is there a way to use a logarithmic scale in the colour legend of a ListContourPlot? The contours can be logged by taking the Log10 of the data, but this doesn't transfer to the legend. As an example, with the code:

test = Flatten[Table[{i, j, Log10[RandomReal[{0, 1*^10}]]}, {j, 1, 100}, {i, 1, 100}], 1];

ListContourPlot[test, InterpolationOrder -> 0, PlotLegends -> Automatic,
Contours -> 20, ColorFunction -> "Rainbow", ColorFunctionScaling -> True,
PlotRange -> All]


I get equally spaced contours for values <7, 8, 9 and 10. Could I plot these data with equally spaced contours corresponding to values 0.1, 1 and 10?

Another example, where you'd expect to see logarithmic data:

test = Flatten[Table[{i, j, Log10@Exp[-(i + j)^2]}, {j, 1, 10}, {i, 1, 10}], 1];
ListContourPlot[test, InterpolationOrder -> 0,
PlotLegends -> Automatic, Contours -> 20, ColorFunction -> "Rainbow",
ColorFunctionScaling -> True, PlotRange -> All]


-
One way is to segment the data into as many sections as you want color resolution, 1) order set 2) divide into k equaly large parts 3) make a function that returns which division a value would lie in divided by number of divisions 4) scale ColorFunctions argument with that manually, I tried implementing this but got stuck here's how far I got –  ssch Dec 17 '12 at 19:28
I wonder if the CustomTicks package can be used here. –  Eli Lansey Dec 17 '12 at 19:34
Misunderstood the question, but I guess you could still pass the divisions to Contours –  ssch Dec 17 '12 at 19:58
Do you get something close to what you need playing with the parameters in PlotLegends -> BarLegend[{"Rainbow", {0, 1}}, Function[{min, max}, Rescale[{.1, 1, 5, 10}, {0, 10}, {min, max}]]]? –  kguler Dec 17 '12 at 22:53
Thank you all for your valuable help! Unfortunately I was not yet able to solve my problem. Using kguler's suggestion, the tick values in the legend are displayed as I would want them, but the colour gradation stays the same - not logarithmic as I would like. To make myself clear, the jump in colour from 0.1 to 1 is smaller than the jump from 1 to 10, and so on. Any further suggestions are appreciated! Thanks –  user5071 Dec 18 '12 at 11:51

I think I found a way to solve the problem.

Using a different example:

test = Flatten[Table[{i, j, Exp[RandomReal[{0, 10}]]}, {j, 1, 100}, {i, 1, 100}], 1];

min = Log[10, Min[test[[;; , 3]]]];
max = Log[10, Max[test[[;; , 3]]]];

ListContourPlot[test,
InterpolationOrder -> 0,
Contours -> Flatten[Table[{1., 2., 5.}*10^n, {n, 1, 4}]],
ColorFunction -> Function[{f}, ColorData["Rainbow"][(Log[10, f] - min)/(max - min)]],
ColorFunctionScaling -> False,
PlotLegends -> BarLegend[Automatic, All],
PlotRange -> All]


The result is

Thank you all for your input!

-