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
    $\begingroup$ How about GridLinesStyle -> Directive[Dotted, Blue] ? $\endgroup$ – OkkesDulgerci Apr 1 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

| improve this answer | |
$\endgroup$
  • $\begingroup$ So, you just drew them... Thanks! $\endgroup$ – Dims Apr 1 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 at 10:17
3
$\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.

| improve this answer | |
$\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

| improve this answer | |
$\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.