Bug introduced in 10.0.0 and fixed in 10.1.0


  • It seems that only versions 10.0.0, 10.0.1, and 10.0.2 are affected by this problem.
  • For 10.0.0 there is no general solution known to me due to Why does GridLines option fail with Function?
  • For versions 10.0.1 and 10.0.2 a solution is the PlotTheme method in my self-answer.
    (The enhanced definition in that answer may still be of general interest.)
  • In version 10.1.0 and later both GridLines -> All and GridLines -> Full produce the desired result, as shown in pmsoltani's now Accepted answer.

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?

  • $\begingroup$ 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 :) $\endgroup$ – Nasser Jul 12 '14 at 9:04
  • $\begingroup$ @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. $\endgroup$ – Mr.Wizard Jul 12 '14 at 9:08
  • $\begingroup$ I was trying to do that, using GridLines->function but I think there is a bug, please see question I just asked on this. $\endgroup$ – Nasser Jul 12 '14 at 9:10
  • $\begingroup$ Are we tagging the howto in v10 questions with version-10 or is that going to get cumbersome quickly? $\endgroup$ – bobthechemist Jul 12 '14 at 15:04
  • $\begingroup$ @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 $\endgroup$ – rm -rf Jul 12 '14 at 15:11

You can, also, use GridLines -> Full option (in version 10.3, at least):

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

semilog plot with full girdlines

  • $\begingroup$ This works in v10.1.0 as well. Thanks! In version 10.1.0 GridLines -> All also works. I am inclined to think that this may have been a transitory bug. $\endgroup$ – Mr.Wizard Mar 1 '16 at 2:26
  • 2
    $\begingroup$ @Mr.Wizard I get A GridLines specification should be None, Automatic, or a list of grid line specifications. M $\endgroup$ – William Mar 1 '16 at 3:32
  • 1
    $\begingroup$ @William Thank you. I recall trying (guessing) multiple alternative values in 10.0.0 before posting this question, so I probably didn't simply forget to try Full. Do you happen to also have access to v10.0.1? That is when the bug fix necessary for my self-answer solution was made, therefore if Full does not work in 10.0.1 my answer still has value, but if it does it fully supplants my method. $\endgroup$ – Mr.Wizard Mar 1 '16 at 3:39
  • $\begingroup$ @Mr.Wizard No I do not. I'm amazed that such changes occurred between the versions of 10.0.0 and 10.0.1 although it is a bug. $\endgroup$ – William Mar 1 '16 at 3:52
  • 1
    $\begingroup$ @William I reinstalled 10.0.1 and 10.0.2 just to check this. Neither All nor Full work. I am updating the question post with the aim of directing users to the best solution. $\endgroup$ – Mr.Wizard Mar 1 '16 at 9:42

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

Enhanced definition

I am finally updating this to answer rcollyer's challenge back in May.

To provide some additional contrast one might wish to style the major division grid lines differently. This will require more elaborate code, but first examples of use:

The Theme used with a parameter:

LogPlot[x^x, {x, 1, 5}, PlotTheme -> {"LogGrid", {Thick, Red}}]

enter image description here

Or by setting a global Option:

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

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

enter image description here

The code needed to effect this:

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

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

logticks[mstyle_][a_, b_] := logticks[a, b, "MajorStyle" -> mstyle]

makeTheme = (
  System`PlotThemeDump`resolvePlotTheme["LogGrid", #] := 
    Themes`SetWeight[{GridLines -> #2, Frame -> True}, 
  System`PlotThemeDump`resolvePlotTheme[{"LogGrid", mstyle_}, #] := 
    Themes`SetWeight[{GridLines -> (#2 /. logticks -> logticks[mstyle]), 
       Frame -> True}, System`PlotThemeDump`$ComponentWeight];
 ) &;

MapThread[makeTheme, {
   {"LogPlot" | "ListLogPlot", 
    "LogLinearPlot" | "ListLogLinearPlot", 
    "LogLogPlot" | "ListLogLogPlot"},
  {{Automatic, logticks}, {logticks, Automatic}, logticks}
  • 2
    $\begingroup$ You could add a parameterization to your theme. For example, Plot[x, {x, 0, 1}, PlotTheme -> {"Monochrome", Red}] . And, no I don't know how it is implemented, but I imagine that won't stop you. :) $\endgroup$ – rcollyer May 10 '16 at 2:39
  • $\begingroup$ @rcollyer Interesting challenge. I'll try to remember to see if I can do it. $\endgroup$ – Mr.Wizard May 11 '16 at 11:11
  • $\begingroup$ @rcollyer Please see my belated update. $\endgroup$ – Mr.Wizard Aug 2 '16 at 12:04
  • 1
    $\begingroup$ Nice. Even works combined with other themes, e.g. LogPlot[x^x, {x, 1, 5}, PlotTheme -> {"Scientific", {"LogGrid", {Red, Dashed, Opacity[1]}}}]. $\endgroup$ – rcollyer Aug 2 '16 at 13:07
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

  • 2
    $\begingroup$ The problem is that hard-coded grid lines have to be adjusted manually for every individual plot. $\endgroup$ – Jens Jul 12 '14 at 18:50
  • 10
    $\begingroup$ 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. $\endgroup$ – Ernst Stelzer Jul 12 '14 at 19:07
  • 5
    $\begingroup$ That would indeed be very nice. There are so many new finance related charting functions etc., but no progress in actual scientific plotting. $\endgroup$ – Jens Jul 12 '14 at 19:29
  • 1
    $\begingroup$ @ErnstStelzer Apparently we have that now, or the easy ability to implement it, as ParametricPlot supports ScalingFunctions (unofficially). See Simon Woods' answer: (55882) $\endgroup$ – Mr.Wizard Jul 27 '14 at 17:10
  • $\begingroup$ @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. $\endgroup$ – Ernst Stelzer Jul 29 '14 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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