1
$\begingroup$

How does one plot piecewise functions, with the ability to plot individual points along with open points to clearly show how values are defined at discontinuities?

Example:

enter image description here Image Credit

with the dashed vertical line omitted.

$\endgroup$
4
  • 2
    $\begingroup$ Related: mathematica.stackexchange.com/questions/39445/… $\endgroup$ – Michael E2 Oct 27 '20 at 18:38
  • $\begingroup$ This plot makes no sense in traditional math, since the so-called HeavisideTheta function is not a usual function, but a distribution (i.e. a certain functional). $\endgroup$ – user64494 Oct 27 '20 at 23:58
  • 1
    $\begingroup$ @user64494 and yet that doesn't matter a lick for the OP $\endgroup$ – b3m2a1 Oct 28 '20 at 2:26
  • $\begingroup$ @b3m2a1: The plot under consideration is a plot of a piecewise function, not HeavisideTheta. Hope I am clear. $\endgroup$ – user64494 Oct 28 '20 at 5:55
2
$\begingroup$

Something to get you started

Plot[HeavisideTheta[x], {x, -1, 1}, 
 ExclusionsStyle -> None,
 Epilog -> {
   {
    FaceForm[None],
    EdgeForm[ColorData[97][1]],
    Disk[{0, 1}, .025]
    },
   {
    ColorData[97][1],
    Disk[{0, .5}, .025]
    },
   {
    FaceForm[None],
    EdgeForm[ColorData[97][1]],
    Disk[{0, 0}, .025]
    }
   },
 Frame -> True,
 Axes -> False,
 ImageSize -> 500
 ]

enter image description here

$\endgroup$
1
$\begingroup$

I don't find the elegant way to un-clipped or un-filled the point,so I have to use White.

Clear[f];
f[x_] := Piecewise[{{1/2, x == 0}}, HeavisideTheta[x]];
Plot[f[x], {x, -5, 5}, 
 Epilog -> {Style[Point[{0, 1/2}], PointSize[Large], Blue], 
   Style[Point[{0, 1}], PointSize[Large], Green], 
   Style[Point[{0, 1}], PointSize[Medium], White], 
   Style[Point[{0, 0}], PointSize[Large], Cyan], 
   Style[Point[{0, 0}], PointSize[Medium], White]}, Axes -> False, 
 Frame -> True]

enter image description here

$\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.