We can use ExclusionsStyle -> {Dashed, AbsolutePointSize[10]}
to style the excluded line and its endpoints without having to know where the discontinuities are.
Examples:
ClearAll[g, h, s]
g[x_] := x^2 Sign[x - 1]
pg = Plot[g[x], {x, 0, 1.5}, ImageSize -> 400,
ExclusionsStyle -> {Dashed, AbsolutePointSize[10]}]
We can post-process to modify/add Point
s:
addPoints = ReplaceAll[p_Point :>
{Point@({1, 0} # & /@ First[p]), p, White, AbsolutePointSize[7], p}];
addPoints @ pg
h[x_] := x^2*Sign[x - 1/2] Sign[1 - x];
addPoints @ Plot[h[x], {x, 0, 1.5}, ImageSize -> 400,
ExclusionsStyle -> {Dashed, AbsolutePointSize[10]}]
s[x_] := Sin[2 Pi x] Sign[1/2 - Sin[2 2 Pi x]];
addPoints @ Plot[s[x], {x, 0, 1.5}, ImageSize -> 400,
ExclusionsStyle -> {Dashed, AbsolutePointSize[10]}]
Update: An alternative way to use addPoints
is to make it the setting for DisplayFunction
in Plot[...]
:
Row[
Plot[#[x], {x, 0, 1.5}, ImageSize -> 400,
ExclusionsStyle -> {Dashed, AbsolutePointSize[10]},
DisplayFunction -> addPoints]& /@
{g, h, s},
Spacer[10]]
Clear[f];f[x_] = Piecewise[{{1, x > 0}, {0, x == 0}, {-1, x < 0}}]
==
instead of=
. Or usingSign
instead. $\endgroup$Plot[g[x], {x, -2, 2}, Exclusions -> x == 1]
, if you do not want a vertical line. You should not call a result wrong simply because you would like the answer in a different format. $\endgroup$