3
$\begingroup$

The following simple code generates a flawed plot:

f[t_] := UnitStep[t - 14.1] + UnitStep[t - 14.5] + UnitStep[t - 14.9]

Plot[f[t], {t, 0, 16}, Filling -> Axis, Exclusions -> None]

enter image description here

I never expected part of the connection is slanted. Although I can fix this issue in many ways (such as using PlotPoints option, changing the plot ranges), this behavior is still surprising to me. Could anyone explain this? (I'm using Mathematica 11.3)

$\endgroup$
1
  • 2
    $\begingroup$ Please try to avoid using the bugs tag unless it has been confirmed as a bug by Wolfram or the community agrees that this is a bug. $\endgroup$
    – MassDefect
    Commented Jun 7, 2019 at 16:08

2 Answers 2

5
$\begingroup$
f[t_] := UnitStep[t - 14.1] + UnitStep[t - 14.5] + UnitStep[t - 14.9]

Adding Exclusions will cause Plot to look closely in the region of the Exclusions and result in clean steps.

Plot[f[t], {t, 0, 16},
 Exclusions -> {14.1, 14.5, 14.9},
 Filling -> Axis]

enter image description here

EDIT: You will get the same result with Exclusions -> True. END EDIT

Or use the option MaxRecursion

Plot[f[t], {t, 0, 16},
 MaxRecursion -> 10,
 Filling -> Axis]

enter image description here

$\endgroup$
4
$\begingroup$

Update: We can use a special form {numberofpoints, {list of points}} for the option setting for PlotPoints as an alternative to setting a very large value (see see this answer by Ullrich Neumann):

Plot[f[t], {t, 0, 16}, Filling -> Axis, 
 PlotPoints -> {50, {14.1, 14.5, 14.9}}, 
 Exclusions -> None]

enter image description here

Original answer:

Add the option PlotPoints with a large value:

Plot[f[t], {t, 0, 16}, Filling -> Axis, Exclusions -> None, 
  PlotPoints -> 200]

enter image description here

Alternatively,

Quiet @ Plot[f[t], {t, 0, 16}, Filling -> Axis, Exclusions -> None, 
  Method -> {"MaxBend" -> 0}]

same picture

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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