4
$\begingroup$

EDIT: I posed this as a version issue but now I think it's (also?) an OS issue. Problem exists on both v10.1 and v11.0 on macOS Sierra, but does not exist on Mr.Wizard's post which is v10.1 (OS unknown), though Mr.Wizard claims to now have the issue as well.

While reading this post and the answer by Mr.Wizard I noticed a difference in plotting behavior between his version and mine that made me unable to reproduce his plot. The meaning of Thickness seems in his case to be the lateral thickness of a line (preserving e.g. Dashing), but in my case to be the omnidirectional thickness of each visual bit of a line (destroying e.g. Dashing).

The code in question (see our exchange in the comments on his answer):

Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi},  PlotStyle -> {{Green, Thickness[.02], Dashing[Tiny]}, {Red, Thickness[Large]}}]

Which in v.10.1 on Windows produced this:

enter image description here

but in any version on macOS Sierra produces this:

enter image description here

He also pointed out that using Directive does not change behavior on either version, i.e.

Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotStyle -> {Directive[Green, Thickness[.02], Dashing[Tiny]], Red}]

does not fix the problem.

So question: Is there a workaround for this? And is this really a bug or am I misunderstanding a new "feature"?

$\endgroup$
  • $\begingroup$ fyi I reported this as a bug to Wolfram $\endgroup$ – Max Apr 18 '17 at 17:01
  • $\begingroup$ OK, but what is your question? Please make it explicit. Also, any time there is a problem like this, do give full version information, including the operating system. On OS X I get the solid looking line in all versions since 10.0 unless I specify CapForm["Butt"]. $\endgroup$ – Szabolcs Apr 18 '17 at 17:54
  • $\begingroup$ Good feedback. I specified the question and noticed the same thing as you that it's on all OS X systems. Mr.Wizard might be able to help here. $\endgroup$ – Max Apr 18 '17 at 18:18
  • $\begingroup$ @Szabolcs And I guess CapForm["Butt"] does answer my question, thanks! $\endgroup$ – Max Apr 18 '17 at 18:27
  • $\begingroup$ Mr Wizard uses Windows. I'll post an answer then, but I am not sure that this is cross-platform behaviour ... $\endgroup$ – Szabolcs Apr 18 '17 at 18:29
3
$\begingroup$

I can reproduce the problem on OS X with versions 10.0-11.1.

It seems to happen because the default line cap setting is CapForm["Square"]. This means that each line segment making up the dashed line will visually extend beyond their endpoints.

A fix that works on OS X is using

CapForm["Butt"]

which ensures that the line segments only extend to their endpoints.

Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, 
 PlotStyle -> {{CapForm["Butt"], Green, Thickness[0.02], 
    Dashing[Tiny]}, {Red, Thickness[Large]}}]

Mathematica graphics

This fixed the problem on-screen, and in PDF or EPS export.

This answer is only for OS X. I expect that Mathematica may behave differently on other operating systems.

$\endgroup$
2
$\begingroup$

I got this response from Wolfram Tech Support that is also a good fix (but not as good as Szabolcs'), though I can't say I see the purpose of such a design choice:

"This is as designed. If you imagine an infinitely thin line extending from pt1 to pt2 and now add thickness in ALL directions you will find that at the end of the line segments the added thicknesses will interfere with each other. You can get around this using Dashing.

Graphics[{Dashing[{.02, .04}], Thickness[.02], 
  Line[{{0, 0}, {1, 1}}]}]

This will work in options such as PlotStyle."

$\endgroup$
0
$\begingroup$
$Version

(*  "11.1.0 for Mac OS X x86 (64-bit) (March 16, 2017)"  *)

Either use Dashing[Large] or specify values.

Manipulate[
 Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, 
  PlotStyle -> {{Green, Thickness[.02], Dashing[d]}, {Red, Thickness[Large]}}],
 {{d, Large}, {Tiny, Medium, Large, {0.05, 0.05}, {0.1, 0.1}}}]

enter image description here

$\endgroup$
  • $\begingroup$ While I agree this kinda works, it doesn't properly speaking give you the intended effect of Dashing, since I believe the dashes and gaps should be of equal length. This might make a good hack for unequal dash patterns? $\endgroup$ – Max Apr 18 '17 at 20:53

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.