2
$\begingroup$

As stated in the title: I am trying to find the reason on the documentation, but maybe I am not able yet to understand it (recently new user). Can anybody tell me why GridLinesdoesn't work if placed as in the following example, but it does if placed out?

 Show[ListLogLogPlot[Table[i, {i, 0, 2}], Joined -> True], 
 GridLines -> All] (*not working*)


 Show[ListLogLogPlot[Table[i, {i, 0, 2}],  GridLines -> All,Joined -> True]] 
 (*working*)
$\endgroup$
3
  • 1
    $\begingroup$ Where is GridLines -> All documented? $\endgroup$
    – Kuba
    Apr 28, 2017 at 13:04
  • $\begingroup$ There are examples such as DateListPlot[mvar, GridLines -> {All, None}, PlotRange -> All, PlotLegends -> {"HP", "IBM"}] in TimeSeriesAggregate, for instance, or DensityPlot[Sin[x + y^2], {x, 0.1, 2}, {y, -2, 2}, RegionFunction -> Function[{x, y, z}, 2 < x^2 + y^2 < 5], ScalingFunctions -> {"Log", None}, FrameTicks -> {{Automatic, Automatic}, {2^Range[-5, 2], Automatic}}, GridLines -> All] in DensityPlot $\endgroup$
    – rhermans
    Apr 28, 2017 at 13:13
  • 1
    $\begingroup$ Automatic instead of All? Show[ListLogLogPlot[Table[i, {i, 0, 2}], Joined -> True], GridLines -> Automatic] does work, AND it is documented. $\endgroup$
    – rhermans
    Apr 28, 2017 at 13:18

1 Answer 1

4
$\begingroup$

Both Show and ListLogLogPlot accept graphics options so GridLines can be an option for both. The observed(no sources other than myself) reason it works when invoked inside the ListLogLogPlot function and not within the Show function is the following:

  • GridLines -> All produces grids intersecting all ticks generated automatically on all axes (i.e. when Ticks -> Automatic)
  • Show seems to be oblivious to the number or location of ticks of the different graphics objects passed to it as inputs so it doesn't understand you when you tell it to put a grid on All ticks. However, GridLines -> Automatic as a Show option will give you gridlines at positions different than your ListLogLogPlot Automatic ticks
  • ListLogLogPlot will generate a figure whose Automatic ticks is known to it and therefore is able to understand what GridLines -> All means

Show[ListLogLogPlot[Table[i, {i, 0, 2}], Joined -> True], 
 GridLines -> Automatic] 

Show[ListLogLogPlot[Table[i, {i, 0, 2}], GridLines -> All, 
  Joined -> True]]

enter image description here]1

$\endgroup$
5
  • $\begingroup$ so do you believe it is always better to state GridLines inside Plot function rather than Show (also, if I have many functions inside Show, maybe it is good to put GridLines in one of those?) $\endgroup$
    – Andrea G
    Apr 28, 2017 at 13:33
  • 1
    $\begingroup$ I would say that it is always better to style ticks and Gridlines in one of the plots instead of Show. If you have many plots inside of Show, format the Gridlines in 1 of the plots (possibly the one covering the bigger range) only. $\endgroup$ Apr 28, 2017 at 13:50
  • 2
    $\begingroup$ Is this an observation or are there any sources you could link? $\endgroup$
    – Kuba
    Apr 28, 2017 at 22:14
  • 1
    $\begingroup$ @Kuba I re-edited the answer so that it is clear that those are observed behaviors. Actually, there is no explanation of what GridLines -> All actually does in the Mathematica documentation. $\endgroup$ Apr 28, 2017 at 22:28
  • $\begingroup$ @AssaadMrad Thanks for clarification. $\endgroup$
    – Kuba
    Apr 29, 2017 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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