How to get grid lines at all (log) tick marks in Version 10?
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]
LogLinearPlot[Log @ x, {x, 1, 500},
GridLinesStyle -> LightGray, PlotTheme -> "LogGrid", Frame -> True]
LogLogPlot[x, {x, 0.1, 15},
GridLinesStyle -> LightGray, PlotTheme -> "LogGrid", Frame -> True]
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}}]
Or by setting a global Option:
SetOptions[logticks, "MajorStyle" -> {Thick, Orange, Opacity[0.5]}];
LogPlot[x^x, {x, 1, 5}
, GridLinesStyle -> LightGray
, PlotTheme -> "LogGrid"
]
The code needed to effect this:
Options[logticks] = {"MajorStyle" -> {}}; (* uniform style by default *)
logticks[a_, b_, OptionsPattern[]] :=
Replace[
Charting`ScaledTicks[{Log, Exp}][a, b],
{{p_, _Spacer, ___} :> Exp[p],
{p_, ___} :> {Exp[p], OptionValue[logticks, "MajorStyle"]}},
{1}
]
logticks[mstyle_][a_, b_] := logticks[a, b, "MajorStyle" -> mstyle]
makeTheme = (
System`PlotThemeDump`resolvePlotTheme["LogGrid", #] :=
Themes`SetWeight[{GridLines -> #2, Frame -> True},
System`PlotThemeDump`$ComponentWeight];
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}
}];
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]
LogPlot[x^x, {x, 1, 5}, GridLinesStyle -> LightGray,
GridLines -> {Range[5],
Flatten[Table[n, {n, 1 #, 9 #, 1 #}] & /@ (10^Range[0, 4])]},
Frame -> True]