Function Repository Resource:

GraphPaperGridLines

Source Notebook

Generate grid lines in graphics in the style of traditional graph paper

Contributed by: Jon McLoone

ResourceFunction["GraphPaperGridLines"][{{xlo,xhi},{ylo,hi}}]

creates the GridLines option for graph paper style lines over the range given by xlo,xhi,ylo,yhi.

ResourceFunction["GraphPaperGridLines"][gr]

shows the Graphics object gr with GridLines in the style of graph paper.

Details and Options

The primary subdivisions are chosen to be the largest power of 10 that allows at least two primary GridLines.
ResourceFunction["GraphPaperGridLines"] supports the following options:
"PrimaryStyle"Graythe style for major grid lines.
"SecondaryStyle"LightGraythe style for minor grid lines.
"SecondaryCount"5the number of subdivisions between each major grid line

Examples

Basic Examples (2) 

Show a plot with graph paper style GridLines:

In[1]:=
ResourceFunction["GraphPaperGridLines"][
 Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic]]
Out[1]=

Generate the option value to give this effect:

In[2]:=
Options[Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic], PlotRange]
Out[2]=
In[3]:=
ResourceFunction["GraphPaperGridLines"][PlotRange /. First[%]]
Out[3]=

Options (2) 

You can change the style of both the primary and secondary GridLines:

In[4]:=
ResourceFunction["GraphPaperGridLines"][
 Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic], "PrimaryStyle" -> Blue, "SecondaryStyle" -> Pink]
Out[4]=

You can change how many subdivisions there are between each primary grid line. Typically values will be 2, 5 or 10:

In[5]:=
ResourceFunction["GraphPaperGridLines"][
 Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic], "SecondaryCount" -> 2]
Out[5]=
In[6]:=
ResourceFunction["GraphPaperGridLines"][
 Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic], "SecondaryCount" -> 10]
Out[6]=

Properties and Relations (2) 

When applied to a Graphics object, the PlotRange of the object is used to calculate the grid:

In[7]:=
ResourceFunction["GraphPaperGridLines"][
 Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic]]
Out[7]=

This is equivalent to:

In[8]:=
gr = Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic];
Show[gr, ResourceFunction["GraphPaperGridLines"][PlotRange[gr]]]
Out[8]=

Possible Issues (2) 

If used within functions with a HoldAll attribute, it is necessary to use Evaluate:

In[9]:=
Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic, ResourceFunction["GraphPaperGridLines"][{{0, 10}, {-3, 3}}]]
Out[9]=
In[10]:=
Plot[3 Sin[ x], {x, 0, 10}, AspectRatio -> Automatic, Evaluate[ ResourceFunction["GraphPaperGridLines"][{{0, 10}, {-3, 3}}]]]
Out[10]=

GridLines are equally spaced in the x and y directions, so if AspectRatio is not Automatic, the spacings will then appear different in the different directions:

In[11]:=
ResourceFunction["GraphPaperGridLines"][Plot[Sin[ x]/3, {x, 0, 10}]]
Out[11]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 25 May 2021

License Information