5
$\begingroup$

I need to denote only dots at grid crossings. How to make this in Mathematice? GridLinesStyle does not contain appropriate option.

$\endgroup$
1
  • 1
    $\begingroup$ How about GridLinesStyle -> Directive[Dotted, Blue] ? $\endgroup$ – OkkesDulgerci Apr 1 '20 at 16:20
5
$\begingroup$

This could be a starting point:

xvals = Range[10];
yvals = Range[-1, 1, 0.2];

Plot[Sin[x], {x, 0, 10},
 Prolog -> {AbsolutePointSize[1], Point@Tuples[{xvals, yvals}]}
 ]

enter image description here

$\endgroup$
2
  • $\begingroup$ So, you just drew them... Thanks! $\endgroup$ – Dims Apr 1 '20 at 18:16
  • 1
    $\begingroup$ @Dims I do not think that there is any other way. GridLines are always lines (possibly with a dashed/dotted style), and you asked for points instead of lines. $\endgroup$ – Szabolcs Apr 3 '20 at 10:17
4
$\begingroup$

Post-processing to replace grid lines with dots aligned with automatically generated ticks:

ClearAll[gL, grdLns, dottedGridlines]
gL[plt_, xy_, spec_: Automatic] := Replace[DeleteDuplicatesBy[
   Charting`FindTicks[{0, 1}, {0, 1}][## & @@ PlotRange[plt][[xy]]][[All, ;; 2]], First],
  {{a_, ""} :> (spec /. {Automatic -> Nothing, Full -> a}), {a_, _} :> a}, 1]

grdLns[plt_][a : {__List}] := Tuples @ a
grdLns[plt_][{a_List, s : (Automatic | Full)}] := Tuples @ {a, gL[plt, 2, s]}
grdLns[plt_][{s : (Automatic | Full), a_List}] :=  Tuples @ {gL[plt, 1, s], a}
grdLns[plt_][s : {(Automatic | Full) ..}] := Tuples @ {gL[plt, 1, s[[1]]], 
    gL[plt, 2, s[[2]]]}
grdLns[plt_][s : (Automatic | Full)] := grdLns[plt][{s, s}]
grdLns[plt_][] := grdLns[plt][Options[plt, GridLines][[1, 2]] /. _Function -> Full]

dottedGridlines = Show[#, Epilog -> Point[grdLns[#][]], GridLines -> None] &;

Examples:

{plt1, plt2, plt3} = Plot[Sin[x], {x, 0, 10}, GridLines -> #, Frame -> True, 
     Axes -> False, ImageSize -> 340, PlotLabel -> "GridLines -> " <> ToString@#] & /@ 
 {Automatic, Full, {Range[2, 6], Automatic}};

Row[{plt1, plt2, plt3}, Spacer[10]]

enter image description here

Row[dottedGridlines /@ {plt1, plt2, plt3}, Spacer[10]]

enter image description here

Note: The option setting Full for GridLines is not documented.

$\endgroup$
1
$\begingroup$
Graphics[Circle[], Axes -> True, GridLines -> Automatic, 
 GridLinesStyle -> Directive[Orange, Dotted]]

dotted grid

Plot[Cos[x], {x, 0, 10}, Ticks -> {None, Automatic}, 
 GridLines -> {{Pi, 2 Pi, 3 Pi}, {-1, -.5, .5, 1}}, 
 GridLinesStyle -> Directive[Gray, Dotted]]

enter image description here

$\endgroup$
1
$\begingroup$

This expands a bit on @Szbolcs answer. I suppose one could calculate the positions of the horizontal and vertical dots automatically. A bit tedious, that would be. It would be nicer if there were a GridLinesStyle Dotted option, but it does not seem to exist.

(*horizontal dots*)
ls1 = ListPlot[Table[{i/10, 0.05 j}, {i, 0, 100}, {j, 0, 10}], PlotStyle -> Black];

(*vertical dots*)
ls2 = ListPlot[Table[{i, 0.01 j}, {i, 0, 10}, {j, 0, 50}], PlotStyle -> Black];

(*whatever curve*)
pl1 = Plot[Sin[y]/4 + 1/4, {y, 0, 10}];

Show[ls1, ls2, pl1]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.