# How to draw dots at beginning and end of range when plotting [duplicate]

I'm trying to plot a Piecewise function which should look like this: How can I have similiar dots (filled or empty) at beginning and end of range?

F[x_] := Piecewise[{{0, -Infinity < x <= -4}, {0.2, -4 < x <= -2}, {0.5, -2 < x <= 2}, {0.9, 2 < x <= 6}}, 1]
Plot[F[x], {x, -6, 10}, PlotTheme -> "Detailed"]


This is how my plot looks like right now: • – Michael E2 Mar 15 '15 at 1:24
• It worked, however I'm surprised it's not included as part of Mathematica and requires external functions. – stil Mar 15 '15 at 1:42

## 1 Answer

Update: Post-processing using custom Arrowheads:

g1 = Graphics[Disk[]];
g2 = Graphics[{EdgeForm[Thick], FaceForm[White], Disk[]}];

plt /. Line[x_] :> {Arrowheads[{{-.01, 0, g2}, {.0125, 1, g1}}], Arrow[x]} Original post:

One approach is to post-process the plot output to add filled and an empty circles to the lines:

f[x_] := Piecewise[{{0, -Infinity < x <= -4}, {0.2, -4 < x <= -2},
{0.5, -2 < x <= 2}, {0.9, 2 < x <= 6}}, 1]
plt=Plot[f[x], {x, -6, 10}, PlotTheme -> "Detailed"];

plt/. Line[x_] :> {Line[x], AbsolutePointSize, Point[Last@x],
AbsolutePointSize, Point[First@x],
{White, AbsolutePointSize, Point[First@x]}} In version 9, you can specify the PlotStyle to add filled and empty circles to Line primitives (this trick doesn't seem to work in version 10):

Plot[f[x], {x, -6, 10}, PlotLegends -> "Expressions",
PlotStyle -> ({#, AbsolutePointSize, Point[Last @@ #],
Point[First @@ #], {White, AbsolutePointSize, Point[First @@ #]}} &)] f2[x_] := Piecewise[{{x^2 - 5, -Infinity < x <= -4}, {x + 5, -4 <  x <= -2},
{10 - x^2, -2 < x <= 2}, {x^2 - 2 x - 4, 2 < x <= 6}}, 10]

Plot[f2[x], {x, -6, 10}, PlotLegends -> "Expressions",
PlotStyle -> ({#, AbsolutePointSize, Point[Last @@ #],
Point[First @@ #], {White, AbsolutePointSize, Point[First @@ #]}} &)] • It's much shorter solution than very long function in another thread. You could just reverse filled and empty dot - they should be opposite directed. – stil Mar 15 '15 at 2:04
• @stil, updated with the fix. – kglr Mar 15 '15 at 2:56
• Very nice. I wonder if you could hide dot when function domain is out of axis bounds. For example, when there is domain between minus infinity and -4, and the x axis is just between -6 and 10, there shouldn't be any dot at x=-6. – stil Mar 15 '15 at 14:51