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

Bug introduced in 10.0.0 and fixed in 10.1.0


Update:

  • 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 final version in that answer with emboldened major lines may 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.

I think the missing functionality in 10.0.x can be considered a bug. Should I tag this as such?


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 6 down vote accepted

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

share|improve this answer
    
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. – Mr.Wizard Mar 1 at 2:26
2  
@Mr.Wizard I get A GridLines specification should be None, Automatic, or a list of grid line specifications. M 10.0.0.0 – Liam Mar 1 at 3:32
1  
@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. – Mr.Wizard Mar 1 at 3:39
    
@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. – Liam Mar 1 at 3:52
1  
@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. – Mr.Wizard Mar 1 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:

MapThread[
  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_] :=
 Replace[
  Charting`ScaledTicks[{Log, Exp}][a, b],
  {{p_, _Spacer, ___} :> 
    Exp[p], {p_, ___} :> {Exp@p, OptionValue[logticks, "MajorStyle"]}},
  {1}
 ]

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
    
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. :) – rcollyer May 10 at 2:39
    
@rcollyer Interesting challenge. I'll try to remember to see if I can do it. – Mr.Wizard May 11 at 11:11
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
2  
The problem is that hard-coded grid lines have to be adjusted manually for every individual plot. – Jens Jul 12 '14 at 18:50
9  
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
5  
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
1  
@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

 
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.