What's the best (most elegant, shortest, easiest to read) way to add minor grid lines to a plot?
Here is an example:
data = Table[{x, Log@x}, {x, 100}];
ListPlot[data, Frame -> True, GridLines -> Automatic]
But this gives gridlines only at the position of the major frameticks. I'm looking for an easy way to automatically generate minor grid lines at the positions of minor frameticks (in a style different from the major gridlines).
Here is an example (yes, made in excel)
I guess I could write half a page of code to generate both the frame ticks and the gridlines, but it seems like an overkill.
I realize this is very similar to this question, but if I have to enter the ranges manually for each plot then I might as well draw my plots in excel.
Answer
Not elegant, but at least it's quite short :)
makeGrid[{minX_, maxX_}, {minY_, MaxY_}, {xStep_, yStep_}] :=
{AbsoluteThickness[.25],
Table[{If[Mod[x, 10] == 0, Black, LightGray],
Line[{{x , -100}, {x , 100}}]}, {x, minX, maxX, xStep}],
Table[{If[Mod[y, 1] == 0, Black, LightGray],
Line[{{-100, y}, {100, y}}]}, {y, minY, MaxY, yStep}]}
ListPlot[data, Frame -> True,
Prolog -> makeGrid[{0, 100}, {0, 10}, {10, .1}]]
Comments
Post a Comment