2
$\begingroup$

What exactly does "offset" mean for a graphics directive of the form Dashing[{d1,d2},offset]?

That is, exactly what is offset from what where?

The Documentation Center seems to take the meaning for granted, except for the single example below, which still does not articulate for me what is offset how where.

   Table[Graphics[{Line[{{0, 0}, {2, 1}}], Dashing[{.1, .05}, o], Red, 
      Opacity[.5], Thickness[.05], Line[{{0, 0}, {2, 1}}]}], 
     {o, {-0.05, 0, 0.05}}]

Does the offset represent the fraction of the total image width by which the first dash from the first of the two ends of the line is pushed away from that first end?

$\endgroup$
3
  • $\begingroup$ Yes, that is correct. $\endgroup$
    – lericr
    Commented Feb 24, 2022 at 21:44
  • $\begingroup$ From the documentation, "offset is specified as a fraction of the total width of the graph, and it may be positive or negative. If offset is not specified, it is 0." $\endgroup$
    – Bob Hanlon
    Commented Feb 24, 2022 at 21:57
  • 1
    $\begingroup$ @BobHanlon: Yes, that says how offset is specified, but it does not say what it means! $\endgroup$
    – murray
    Commented Feb 25, 2022 at 22:27

1 Answer 1

2
$\begingroup$

Edit

The offset is the movement of the dash(but need to $\mod (r1+r2)$). Just like a TranslationTransform[offset] or similar with RotateLeft.

enter image description here

r1 = 2/3;
r2 = 1/3;
Manipulate[
 Graphics[{Line[{{0, 0}, {1, 0}}], Dashing[{r1, r2}, offset], 
   Opacity[.3], Thickness[.25], Red, Line[{{0, 0}, {1, 0}}]}, 
  PlotRange -> {{0, 1}, {-.2, .2}}], {offset, 0, r1 + r2}, 
 ControlPlacement -> Top]

enter image description here

Original

A long comment.

  • For arbitrary positive or negative offset, the final offset is the remainder on division of r1+r2 by offset. For example, offset=9, r1 = .1;r2 = .05;,then the final offset is
r1 = .1;
r2 = .05;
offset=9;
Mod[offset,r1+r2,0]
( * 0.15 *)

We can see they are the same in the animation.

r1 = .1;
r2 = .05;
Manipulate[
 Show[Plot[Sin[x], {x, 0, 3 π}, 
   PlotStyle -> Dashing[{r1, r2}, offset]], 
  Plot[Sin[x], {x, 0, 3 π}, 
   PlotStyle -> {Opacity[.2], Red, Thickness[.03], 
     Dashing[{r1, r2}, Mod[offset, r1 + r2, 0]]}]], {offset, 0, 
  2 (r1 + r2)}, ControlPlacement -> Top]

enter image description here

  • If we set {r1,r2},offset, then {r2,r1},r2+offset is the complement.

enter image description here

r1 = .1;
r2 = .05;
Manipulate[
 Show[Plot[Sin[x], {x, 0, 3 π}, 
   PlotStyle -> Dashing[{r1, r2}, offset]], 
  Plot[Sin[x], {x, 0, 3 π}, 
   PlotStyle -> {Opacity[.2], Red, Thickness[.03], 
     Dashing[{r2, r1}, r2 + offset]}]], {offset, 0, 10}]

enter image description here

  • But I still don't understand the meaning of the size of r1=2/3 and r2=1/3 etc. The difference results as below still confuse me.
r1 = 2/3;
r2 = 1/3;
offset = 0;
{Plot[Sin[x], {x, 0, 3}, 
   PlotStyle -> {Red, Dashing[{r1, r2}, offset]}], 
  Plot[x, {x, 0, 3}, PlotStyle -> {Red, Dashing[{r1, r2}, offset]}], 
  Plot[0, {x, 0, 3}, 
   PlotStyle -> {Red, Dashing[{r1, r2}, offset]}]} // GraphicsRow

enter image description here

$\endgroup$
4
  • $\begingroup$ r1 and r2 are specified in the documentation as a fraction of the total width of the graph. And this is exactly what they are. Try with r1 = r2 = .1 and compare plots of $0$ and $\sin x$. There are exactly 5 red and 5 blank patches in the straight line (10 in total, therefore each with length 0.1). And the lengths of the patches are the same in $\sin x$, but there is more of them because the curve is longer in total. Maybe you can add this to your answer to make it complete :-) $\endgroup$
    – Domen
    Commented Feb 26, 2022 at 14:43
  • $\begingroup$ @Domen Thanks, Maybe I can draw another animate to illustrate this later. $\endgroup$
    – cvgmt
    Commented Feb 26, 2022 at 15:05
  • $\begingroup$ @Domen But Sin[x] have 11 parts. I don't understand it. r1 = .1; r2 = .1; Plot[Sin[x], {x, 0, 10}, PlotStyle -> {Opacity[.2], Red, Thickness[.01], Dashing[{r1, r2}, 0]}, AxesOrigin -> {0, 0}, PlotRange -> All] $\endgroup$
    – cvgmt
    Commented Feb 27, 2022 at 1:31
  • 1
    $\begingroup$ Then the in-comment reply, "Yes, that is correct," to my question "Does the offset represent the fraction of the total image width by which the first dash from the first of the two ends of the line is pushed away from that first end?" is wrong! The offset pushes the dash not away from, but toward the beginning of the line, according to the Edit in this answer. Which all goes to show why an actual explanation of "offset" is sadly missing, and needed, in the Documentation Center! $\endgroup$
    – murray
    Commented Feb 27, 2022 at 16:12

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