Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way of generating a density plot (or something similar) with one of its axes on a log scale? Essentially I'm trying to combine a LogLinearPlot and a normal Plot on two different variables to create the associated density plot.

If this can't be done directly, what would be the best work-around?

share|improve this question
If you add a small self-contained example you will get more/better answers. – Ajasja Feb 1 '13 at 13:00
I can't think of an easier workaround than: DensityPlot[f[x,y], {x, Xmin, Xmax}, {y, Ymin, Ymax}] to DensityPlot[f[x, E^y],{x, Xmin, Xmax}, {y, Log@Ymin, Log@Ymax}]. Adding ticks along y might take you some time but it shouldn't be hard (I've assumed that's the direction you want to log plot) – gpap Feb 1 '13 at 13:13
I think ScalingFunctions works with DensityPlot... That might help. – cormullion Feb 1 '13 at 17:32
@cormullion Could you give an example? I can only get it working for the function value but not the axis. (Something like DensityPlot[Sin[x] Sin[y], {x, 1, 10}, {y, 1, 10}, ScalingFunctions -> "Log"]) – Silvia Feb 1 '13 at 18:50
@silvia no I can't (:-() but I thought there might be those who were clever enough to make it happen... – cormullion Feb 1 '13 at 19:16
up vote 2 down vote accepted

Thanks for the input in the comments; here's what I eventually came up with (including tick placement):

fSpace[min_, max_, steps_, f_: Identity] := 
 InverseFunction[f] /@ 
  Range[f@min, f@max, (f@max - f@min)/(steps - 1)]
GetMajorTicks[min_, max_, count_, f_: Identity] := 
  fSpace[min, max, count, f];
GetMinorTicks[min_, max_, majorCount_, minorCount_, f_: Identity] := 
       x ((f@max - f@min)/(majorCount - 1) // InverseFunction[f]), 
       minorCount + 2], 1], -1], {x, 
     Drop[GetMajorTicks[min, max, majorCount, f], -1]}]];

xMin = 1/4;
xMax = 4;
xMajorTicks = 5;
xMinorTicks = 3;
f = Log;
 Sin[2 \[Pi] y] InverseFunction[f]@x, {x, f@xMin, f@xMax}, {y, -1, 1},
  FrameTicks -> {{Automatic, 
    None}, {({f@#, # // N} & /@ 
       GetMajorTicks[xMin, xMax, xMajorTicks, f])~
     Join~({f@#, Null, {0.005, 0}} & /@ 
       GetMinorTicks[xMin, xMax, xMajorTicks, xMinorTicks, f]), 

The plot

If this can be cleaned up or improved in any way, I'd love to hear!

share|improve this answer

Your Answer


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.