Fanning Software Consulting

General Problems with Log Axes

QUESTION: This question appears in numerous forms. Here is a typical one.

I want to plot data on a graph with the left Y-axis as the pressure (in logarithmic units) and the second, right Y-axis as the altitude (in non-logarithmic units). I'm trying to do this this way:

   Plot, o_arr, 10^(alt_arr), YLog=1, YStyle=9, YTitle='Pressure'
   Axis, YAxis=1, YStyle=1, YRange=[0,40], YTitle='Altitude'
but I get a warning about an infinite range and it fails to work. Why is this? I don't understand. It must have something to do with the log plot, I guess, but even with a YLog=0 as parameter to Axis it won't work.

Can someone help me out ?

ANSWER: This is a common problem that often occurs when we work with log axes. The problem is that log axes are "sticky", unlike almost everything else in IDL. Once you do something with logarithmic axes, IDL appears to remember it forever. (Probably holding it against you, for all I know.)

To correct this problem, you have to "unstick" the log axis before you make your Axis call. You need to reset the Type field of the axis system variable, like this:

   Plot, o_arr, 10^(alt_arr), YLog=1, YStyle=9, YTitle='Pressure'
   !Y.Type = 0
   Axis, YAxis=1, YStyle=1, YRange=[0,40], YTitle='Altitude', /Save

Be sure you set the Save keyword on your Axis command. This makes it possible to overplot data using the new, non-logarithmic data coordinates. If you forget this, the scaling factors (!Y.S) from the initial Plot command will still be in effect and your data will not go onto the plot in the way you expect it to.

[Return to IDL Programming Tips]