# How to ask Mathematica to plot a rectangular grid with red points on all crossings?

How can I ask Mathematica to plot a rectangular grid (similar to the attached picture) with those red points on all crossings?

• You tagged it graphs etc., so maybe GridGraph[{5, 4}, VertexStyle -> Red]? Oct 30, 2021 at 0:45
• @MichaelE2 Is not this network a graph? The code you mention gives a square network not rectangular. Oct 30, 2021 at 0:56
• All that can be adjusted. Show@GridGraph[{6, 7}, VertexStyle -> Red] /. GraphicsComplex[_, r__] :> GraphicsComplex[Tuples[N@{Range@7, 2 Range@6}], r] and GridGraph has an option VertexCoordinates, if you want a graph as indicated by the tag. Oct 30, 2021 at 1:00

Clear[a, b, f, dx, dy];
{a, b} = {2, 3};
{dx, dy} = {Subdivide[0, a, 8], Subdivide[0, b, 5]};
f[x_, y_] = {x, y};
ParametricPlot[f @@ {x, y}, {x, 0, a}, {y, 0, b}, Mesh -> {dx, dy},
Epilog -> {PointSize[Large], Red, Point[f @@@ Tuples[{dx, dy}]]},
Frame -> False, Axes -> False, PlotStyle -> None,
MeshStyle -> Directive[AbsoluteThickness[3], Opacity[1], Black]]


We can test another function f[x_, y_] = {x^2 - y^2, x + y};

Make a table, modify range and increments:

t = Table[{x, y}, {x, 1, 4}, {y, 1, 4}]


Combine the following as needed:

g1 = Graphics@Line[#] & /@ t;
g2 = Graphics@Line[#] & /@ Transpose@t;
g3 = Graphics[{Red, PointSize[0.02], Point /@ t}];

Show[g1, g2, g3, Frame -> True, PlotRange -> {{0, 8}, {-1, 6}},
AspectRatio -> Automatic]


Using Epilog or Prolog, the graphic (or parts of it) can be placed on a plot as required.

EDIT

Point grid can be changed in x and y directions; e.g., try:

t = Table[{x, y}, {x, Range[1, 5, 2]~Join~Range[9, 16, 3]}, {y, 1, 4}]


along with a slight change of plot range:

Show[g1, g2, g3, Frame -> True, PlotRange -> {{0, 18}, {-1, 6}},
AspectRatio -> Automatic]