1
$\begingroup$

Suppose I define

f[x] := Piecewise[{{1.7*10^-6, 150 <= x <= 200}}, 0]

and then plot

Plot[Evaluate[f[x]], {x, 0, 1000}, PlotStyle -> {Red, Thick},
     ExclusionsStyle -> {Dashed, Red}]

I get an interrupted dashed vertical line on left

Plot of Piecewise function with Exclusion dashed line missing

Anyone know why this happens and how to draw the entire dashed line?

$\endgroup$
  • 1
    $\begingroup$ Just increase your PlotPoints e.g. PlotPoints->100. $\endgroup$ – Spawn1701D Apr 18 '13 at 21:02
  • $\begingroup$ Very trivial to worth an answer. If you want just upvote the comment instead. Cheers! $\endgroup$ – Spawn1701D Apr 18 '13 at 21:45
1
$\begingroup$

Mathematica's plot algorithms are not optimized when values become very large or in your case very small. You could include your plot in a Manipulate to see the behavior when you adjust e.g. PlotPoints

f[x_] := Piecewise[{{1.7*10^-6, 150 <= x <= 200}}, 0];
Manipulate[
 Plot[Evaluate[g[x]], {x, 0, 1000}, PlotStyle -> None, 
  ExclusionsStyle -> {Dashed, Red}, PlotPoints -> n, 
  PerformanceGoal -> "Quality", Mesh -> All],
 {n, 20, 100, 1}]

enter image description here

And now you could replace your function f with an equivalent function g which returns 1 and not the very small number. Then you'll see the the plot behaves much better with different settings for PlotPoints

g[x_] := Piecewise[{{1, 150 <= x <= 200}}, 0]
$\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.