is an option for two-dimensional graphics functions that specifies grid lines.
GridLines
is an option for two-dimensional graphics functions that specifies grid lines.
Details
- The following settings can be given for GridLines:
-
None no grid lines drawn Automatic grid lines placed automatically {xgrid,ygrid} grid lines specified separately in each direction - With the Automatic setting, grid lines are usually placed at points whose coordinates have the minimum number of digits in their decimal representation.
- For each direction, the following grid line options can be given:
-
None no grid lines drawn Automatic grid line positions chosen automatically {x1,x2,…} grid lines drawn at the specified positions {{x1,style1},…} grid lines with specified styles func a function to be applied to xmin, xmax to get the grid line option - Grid line styles can involve any graphics directives, such as RGBColor and Thickness.
- The grid line function func[xmin,xmax] may return any other grid line option.
- AbsoluteOptions gives the explicit form of GridLines specifications when Automatic settings are used.
- GridLinesStyle gives default styles to use for grid lines.
Examples
open all close allBasic Examples (4)
Put grids across a 2D graphic:
Graphics[Circle[], Frame -> True, GridLines -> Automatic]Draw grid lines at the specific positions:
Plot[Cos[x], {x, 0, 10}, GridLines -> {{Pi, 2Pi}, {-1, -.5, .5, 1}}]Plot[Cos[x], {x, 0, 10}, GridLines -> {{{Pi, Dashed}, {2Pi, Thick}}, {{-1, Orange}, -.5, .5, {1, Orange}}}]Specify overall grid lines style using GridLinesStyle:
Graphics[Circle[], Frame -> True, GridLines -> Automatic, GridLinesStyle -> Directive[Orange, Dashed]]Scope (6)
GridLines Positions (3)
Place the grids automatically:
Graphics[Circle[], Axes -> True, GridLines -> Automatic]Plot[Cos[x], {x, 0, 10}, GridLines -> Automatic]LogLogPlot[1 / x, {x, 1, 100}, GridLines -> Automatic, Frame -> True]Place the grids in the
direction:
Graphics[Circle[], Frame -> True, GridLines -> {Automatic, None}]Place the grids in the
direction:
Plot[Cos[x], {x, 0, 10}, GridLines -> {None, Automatic}]Draw grid lines at specific positions:
Graphics[Circle[], Axes -> True, GridLines -> {{-1, 1}, {-1, 1}}]Plot[Cos[x], {x, 0, 10}, Ticks -> {None, Automatic}, GridLines -> {{Pi, 2Pi, 3Pi}, {-1, -.5, .5, 1}}]GridLines Styling (3)
Specify the style of each grid line:
Graphics[Circle[], Axes -> True, GridLines -> {{-1, {-.5, Dotted}, {.5, Dotted}, 1}, {-1, {-.5, Dotted}, {.5, Dotted}, 1}}]Plot[Cos[x], {x, 0, 10}, Ticks -> {None, Automatic}, GridLines -> {{{Pi, Dashed}, {2Pi, Directive[Red, Thick]}, 3Pi}, {{-1, Blue}, -.5, .5, {1, Blue}}}]Specify overall grid lines style using GridLinesStyle:
Plot[Cos[x], {x, 0, 10}, Ticks -> {None, Automatic}, GridLines -> {{Pi, 2Pi, 3Pi}, {-1, -.5, .5, 1}}, GridLinesStyle -> Directive[Orange, Dashed]]Individually styled grid lines can be used with GridLinesStyle and have higher priority:
Plot[Cos[x], {x, 0, 10}, Ticks -> {None, Automatic}, GridLines -> {{{Pi, Dashing[{}]}, {2Pi, Directive[Blue, Thick]}, {3Pi, Red}}, Automatic}, GridLinesStyle -> Directive[Orange, Dashed]]Generalizations & Extensions (1)
Applications (3)
Put a solid line at each integer, and a dashed line in between:
grids[min_, max_] := Join[Range[Ceiling[min], Floor[max]], Table[{j + .5, Dashed}, {j, Round[min], Round[max - 1], 1}]]Graphics[{Circle[{0, 0}, 2]}, Frame -> True, GridLines -> grids]grids[min_, max_] := Join[Range[Ceiling[min], Floor[max]], Table[{j + .5, Dashed}, {j, Round[min], Round[max - 1], 1}]]Plot[Cos[Pi x], {x, 0, 3}, GridLines -> grids, Background -> StandardBlue]Grid lines on all the integer values:
Graphics[Raster[Table[Append[RandomReal[1, 3], .5], {20}, {20}]], Frame -> True, GridLines -> Function[{min, max}, Range[Floor[min], Ceiling[max]]]]Properties & Relations (3)
Grid lines are placed on the major ticks by default:
{Graphics[Circle[], Frame -> True], Graphics[Circle[], Frame -> True, GridLines -> Automatic]}{Plot[Cos[x], {x, 0, 2Pi}], Plot[Cos[x], {x, 0, 2Pi}, GridLines -> Automatic]}Grid lines are always drawn below all the graphics:
Graphics[{Pink, Disk[]}, Frame -> True, GridLines -> Automatic]Mesh and MeshFunctions can be used to draw lines on top of a certain plot:
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, Mesh -> {3, 3}]DensityPlot[Sin[x] + Cos[y], {x, 0, 8}, {y, 0, 8}, Mesh -> {{2, {4, Thick}, 6}, {2, {4, Thick}, 6}}]ListPlot3D[RandomReal[1, {10, 10}], InterpolationOrder -> 2, Mesh -> 5, MeshFunctions -> (#3&)]Possible Issues (1)
In some plots, grid lines can be completely occluded by the image:
DensityPlot[Sin[x] + Cos[y], {x, 0, 8}, {y, 0, 8}, GridLines -> {{2, {4, Red}, 6}, {2, {4, Red}, 6}}]Mesh can be used instead to place the lines above the graphic:
DensityPlot[Sin[x] + Cos[y], {x, 0, 8}, {y, 0, 8}, Mesh -> {{2, {4, Red}, 6}, {2, {4, Red}, 6}}]See Also
Ticks FrameTicks FaceGrids Frame GridLinesStyle Axes MeshFunctions PolarGridLines
Function Repository: GraphPaperGridLines
Tech Notes
Related Guides
History
Introduced in 1991 (2.0) | Updated in 2007 (6.0)
Text
Wolfram Research (1991), GridLines, Wolfram Language function, https://reference.wolfram.com/language/ref/GridLines.html (updated 2007).
CMS
Wolfram Language. 1991. "GridLines." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/GridLines.html.
APA
Wolfram Language. (1991). GridLines. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GridLines.html
BibTeX
@misc{reference.wolfram_2026_gridlines, author="Wolfram Research", title="{GridLines}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/GridLines.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_gridlines, organization={Wolfram Research}, title={GridLines}, year={2007}, url={https://reference.wolfram.com/language/ref/GridLines.html}, note=[Accessed: 13-June-2026]}