While plotting Plot[Ceiling[FractionalPart[x]], {x, 0, 3}]
I noticed that the dips at integers were not being plotted. Is there a way to achieve that?
$\begingroup$
$\endgroup$
3
-
1$\begingroup$ Probably not. Plot[] does discrete sampling and it’s unlikely it would detect the integer values. Further it tends to exclude discontinuities, so if detected, would skip them. Look up PlotPiecewise on this site for one approach $\endgroup$– Michael E2Commented Dec 21, 2019 at 0:21
-
$\begingroup$ @MichaelE2 the code at mathematica.stackexchange.com/questions/39445/… does the job but is mighty long. Is that the PlotPiecewise you alluded to or some in-built? $\endgroup$– lineageCommented Dec 21, 2019 at 0:28
-
$\begingroup$ Yep, that’s it. It is long. $\endgroup$– Michael E2Commented Dec 21, 2019 at 0:30
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
3
Use the options Exclusions
, PlotPoints
and Method
as follows:
Plot[Ceiling[FractionalPart[x]], {x, 0, 3},
PlotPoints -> {30, Range[0, 3]},
Exclusions -> None,
Method -> {"BoundaryOffset" -> False}]
Alternatively, use ParametricPlot
with the options Exclusions
and PlotPoints
:
ParametricPlot[{x, Ceiling[FractionalPart[x]]}, {x, 0, 3},
PlotPoints -> {30, Range[0, 3]},
Exclusions -> None]
Note the special form of the option value for PlotPoints
(see see this answer by Ullrich Neumann).
-
1$\begingroup$ could you please explain what
PlotPoints -> {30, Range[0, 3]}
means? $\endgroup$– lineageCommented Dec 21, 2019 at 0:38 -
3$\begingroup$ @lineage, it says sample 30 points in the domain but also include the points
{0,1,2,3}
. $\endgroup$– kglrCommented Dec 21, 2019 at 0:40 -
2$\begingroup$ @kglr that’s a really neat undocumented feature! I’d never seen it before; thank for bringing it to my attention! $\endgroup$– MarcoBCommented Dec 21, 2019 at 5:18