Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

How does one set a logarithmic scale for both x and y axes in ContourPlot in Mathematica?

share|improve this question
up vote 35 down vote accepted

One possibility is to plot the contour plot with linear scales using ContourPlot and use ListLogLogPlot to transform this plot to one with logarithmic scales:

pl = Normal@
  ContourPlot[
   Sin[3 x] + Cos[3 y] == 1/2, {x, .01 Pi, 3 Pi}, {y, .01 Pi, 3 Pi}, 
   PlotPoints -> 30]

Mathematica graphics

ListLogLogPlot[Cases[pl, Line[a_, b___] :> a, Infinity], 
 Joined -> True, Frame -> True, PlotRange -> All, AspectRatio -> 1, 
 PlotStyle -> ColorData[1][1]]

Mathematica graphics

share|improve this answer
1  
I keep missing the fun questions. Nice answer. +1 – Mr.Wizard May 7 '12 at 8:56
    
Great idea! I never thought of that. – sebhofer May 7 '12 at 15:15
5  
One disadvantage this method might have is that of point sampling. The right hand and the upper parts are better sampled than the left hand and lower parts of the plot. This might lead to curves that are less smooth on one side than on the other. – Sjoerd C. de Vries May 7 '12 at 17:33
1  
I think that there are actually a lot of other limitations... It's a pity the scaling functions are still not available to this type of plot... For instance, as long as we choose a simple option like ContourLabels, everything becomes more messy... – P. Fonseca May 1 at 10:29

Instead of doing some transformation on the original ContourPlot we can do an exponential rescaling of the original variables in the ContourPlot, so this is somewhat different approach to get roughly the same result :

ContourPlot[ Sin[ 3 Exp@x] + Cos[ 3 Exp@y ] == 1/2, 
             {x, Log[0.01 Pi], Log[3 Pi]}, {y, Log[0.01 Pi], Log[3 Pi]}, PlotPoints -> 30]

enter image description here

The only difference is a different coordinate system.

share|improve this answer

As a slight variation of the nice suggestion above add FrameTicks to get the tick labels you want.

ContourPlot[
 Sin[3 Exp[x]] + Cos[3 Exp[y]] == 1/2, {x, Log[0.01 Pi], 
  Log[3 Pi]}, {y, Log[0.01 Pi], Log[3 Pi]}, PlotPoints -> 30, 
 FrameTicks -> {Table[{y, ToString[Round[10^y, 0.001]]}, {y, 
     Log[10, 0.001], Log[10, 100]}], 
   Table[{y, ToString[Round[10^y, 0.001]]}, {y, Log[10, 0.001], 
     Log[10, 100]}]}]
share|improve this answer
4  
Your example uses a base-E log scale for the plotting and a base-10 log scale for the ticks. Shouldn't these be consistent? – Sean Madsen Nov 16 '13 at 4:16

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.