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

In Version 7 using GridLines -> Automatic (or All) would put a grid line at every log-spaced tick mark:

LogPlot[x^x, {x, 1, 5},
 GridLinesStyle -> LightGray,
 GridLines -> Automatic, 
 Frame -> True]

enter image description here

In Version 10 this is no longer the case:

enter image description here

What is the simplest way to recover the old behavior?

share|improve this question
Nice plot from Version 7, why did WRI remove this features from LogPlot? But trying something I think I found a problem. Posting question now :) – Nasser Jul 12 '14 at 9:04
@Nasser I suppose they consider the new form more clean, but I rely on that feature to clearly see the values on log plots. If there is no simple method I'll have to code a GridLines function to do it. – Mr.Wizard Jul 12 '14 at 9:08
I was trying to do that, using GridLines->function but I think there is a bug, please see question I just asked on this. – Nasser Jul 12 '14 at 9:10
Are we tagging the howto in v10 questions with version-10 or is that going to get cumbersome quickly? – bobthechemist Jul 12 '14 at 15:04
@bobthechemist Please untag them when you see them... I don't know who started this trend, but that is not how we were doing things before. A exceptions can be made when it has been confirmed as a bug by the community – R. M. Jul 12 '14 at 15:11
up vote 12 down vote accepted

Now that specifying a GridLines function has been repaired we can use this:

logticks[a_, b_] := First /@ Charting`ScaledTicks[{Log, Exp}][a, b] // Exp;

Note that a slightly different option value is needed for each plot type. One could make these options the default using SetOptions, but if you prefer to keep the existing default and simplify application of this style I propose a custom PlotTheme:

  Themes`AddThemeRules["LogGrid", #, GridLines -> #2, Frame -> True] &,
    {LogPlot | ListLogPlot, LogLinearPlot | ListLogLinearPlot, LogLogPlot | ListLogLogPlot},
    {{Automatic, logticks}, {logticks, Automatic}, logticks}

Now you can enable this style for any log plot using PlotTheme -> "LogGrid":

LogPlot[x^x, {x, 1, 5},
  GridLinesStyle -> LightGray, PlotTheme -> "LogGrid", Frame -> True]

enter image description here

LogLinearPlot[Log @ x, {x, 1, 500},
  GridLinesStyle -> LightGray, PlotTheme -> "LogGrid", Frame -> True]

enter image description here

LogLogPlot[x, {x, 0.1, 15},
  GridLinesStyle -> LightGray, PlotTheme -> "LogGrid", Frame -> True]

enter image description here

To provide some additional contrast one might wish to style the major division grid lines differently. Here is an alternate definition for logticks to effect this.

Options[logticks] = {"MajorStyle" -> {}};   (* uniform style by default *)

logticks[a_, b_] :=
  Charting`ScaledTicks[{Log, Exp}][a, b],
  {{p_, _Spacer, ___} :> 
    Exp[p], {p_, ___} :> {Exp@p, OptionValue[logticks, "MajorStyle"]}},

Now set a style:

SetOptions[logticks, "MajorStyle" -> {Thick, Orange, Opacity[0.5]}];

And the result:

LogPlot[x^x, {x, 1, 5},
 GridLinesStyle -> LightGray,
 PlotTheme -> "LogGrid", 
 Frame -> True

enter image description here

share|improve this answer
LogPlot[x^x, {x, 1, 5}, GridLinesStyle -> LightGray, 
 GridLines -> {Range[5], 
   Flatten[Table[n, {n, 1 #, 9 #, 1 #}] & /@ (10^Range[0, 4])]}, 
 Frame -> True]

Gridlines in LogPlot

share|improve this answer
The problem is that hard-coded grid lines have to be adjusted manually for every individual plot. – Jens Jul 12 '14 at 18:50
Of course I agree. I am in fact very unhappy with the various Log???Plot functions. In my opinion there should be a single Plot (and a single Plot3D) function, which is supplemented by ScalingFunction->{"Lin", "Log"} or something very similar. – Ernst Stelzer Jul 12 '14 at 19:07
That would indeed be very nice. There are so many new finance related charting functions etc., but no progress in actual scientific plotting. – Jens Jul 12 '14 at 19:29
@ErnstStelzer Apparently we have that now, or the easy ability to implement it, as ParametricPlot supports ScalingFunctions (unofficially). See Simon Woods' answer: (55882) – Mr.Wizard Jul 27 '14 at 17:10
@Mr.Wizard Thank you very much for the hint. It actually works inside Plot. I managed to crash the kernel with some combinations but "Reverse" worked too. – Ernst Stelzer Jul 29 '14 at 13:30

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.