Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]

Mathematica graphics

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]

Mathematica graphics

share|improve this question
    
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
add comment

1 Answer 1

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

enter image description here

Thank you all for your input!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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