Skip to content

Grids and graduated lines ​

These two figures are written in the code like the others, but they have no effect on the graph: its own axes and its own grid are set by the parameters of the graph (axis, grid). The figures here are extra ones: a grid on a part of the plane, a graduated line that is not an axis.

KeyMakes
grida grid, on the whole window or on a part of it
axisa line with an arrow, graduated like an axis

grid: a grid ​

g=grid
g=grid 0.5
g=grid 0:5,0:3
g=grid -2pi:2pi,-1:1,pi/2
g=grid 0:5,0:3,0.5;1
ValueDescription
x,ytwo intervals min:max (the bounds can be written with pi): the part that has the grid. Without them, the whole window
stepa number (both axes), a number of π (pi/3; pi is π/2; for the x axis, the y axis keeps 1) or a vector sx;sy. 1 by default
pidraw
a=grid 0:5,0:3->color=gray
b=grid 5.5:6.5,3.5:4.5,0.25->red

Without values, the grid covers the whole window, with a step of 1. A number alone is the step of both axes:

pidraw
a=grid->gray
b=grid 0.5->red

The lines of a part are at the multiples of the step, so they line up with the grid of the graph, and on the edges of the part, which make a frame. Lines that are less than 3 pixels apart are not drawn. The grid is under all the figures.

pidraw
g=grid -2:2,-2:2,0.5->color=gray

The step can be a vector, one step for each axis:

pidraw
g=grid 0:6,0:4,2;1->gray

A step in π gives the grid of a trigonometric plot:

pidraw
g=grid -2pi:2pi,-1:1,pi/2->gray
f(x)=sin(x)->red

Subdivisions ​

The option subgrid cuts each step in 2 parts, or in n with subgrid=n (an integer from 2 to 20), with lines of the same color, twice as light.

pidraw
g=grid 0:6,0:4->subgrid=4,color=gray

axis: a graduated line ​

a=axis A,B
a=axis A,B,0.5
a=axis A,B,pi/2

The line goes through A, which is its zero, and B, which is its unit. It has an arrow at its end, and a tick with its number at each step, on both sides of the zero (the 0 is written). The numbers are on the right of the line seen in the direction from A to B (under a line that goes to the right). The step is a number, or a number of π (pi/3; pi is π/2).

pidraw
A(0,0)
B(1,0)
a=axis A,B
pidraw
A(0,3)
B(2,3)
C(0,0)
D(1,1)
a=axis A,B,0.5->red
b=axis C,D->blue

With a step in π, the numbers are fractions of π.

pidraw
A(0,0)
B(1,0)
a=axis A,B,pi/2->green

Options ​

The colors, the width and the dashes are the common options, and the numbers and the name have the color of the line. Six more options set the graduation and the extent:

OptionDescription
ticks=n, ticks=first, ticks=n/firstwhich ticks are drawn: the multiples of n (the index is 0 at the zero, 1 at the first tick), the first one only, or both
numbers=n, numbers=first, numbers=n/first, numbers=noneon which ticks a number is written (all the ticks stay drawn); none writes no number
name=tthe name written at the end of the arrow, on the side without numbers
side=leftthe numbers are on the other side (right: under a line that goes to the right)
padding=40the distance to the edges of the window, in pixels (20 by default)
range=-2:5, range=3the part of the line that is drawn, in units from its zero (3 is -3:3). The arrow is at the end of the range, and the graduation stays inside of it

A selection without a step graduates the line with a step of 1. Without numbers, the numbers are thinned out when they would touch, and a selection that you write is taken as it is.

pidraw
A(0,0)
B(1,0)
C(0,2)
D(1,2)
E(0,4)
F(1,4)
G(0,6)
H(1,6)
a=axis A,B->ticks=first
b=axis C,D->numbers=5/first,red
c=axis E,F->ticks=2,name=t,blue
d=axis G,H->side=left,padding=40,green
pidraw
A(0,0)
B(1,0)
a=axis A,B->range=-0.5:5,ticks=1
pidraw
A(0,0)
B(1,0)
a=axis A,B->numbers=none

Mistakes ​

pidraw
A(0,0)
B(1,0)
g=grid 0:5
h=grid 0:5,0:3,x
a=axis A
b=axis A,B,x
c=axis A,B->ticks=x
d=axis A,B->side=up
LineWhat is wrong
3an interval needs the other one
4the step is a number, a number of π or a vector
5an axis wants two points
6the step is a number or a number of π
7ticks takes a number, first, or both
8side is left or right

Released under the MIT License.