7
$\begingroup$

how can I get a plot like this?

enter image description here

I tried with in Mathematica 13.0:

f[x_] := Piecewise[{{x + 1, x < 2}, {x + 1, x > 2}}]
Plot[f[x], {x, -1, 4}, Exclusions -> {2}]

but my output is: enter image description here

Someone can help me pls? thanks

$\endgroup$
1

1 Answer 1

7
$\begingroup$

Since you're willing to use Exclusions, you might also want to use ExclusionsStyle:

Plot[f[x], {x, -1, 4}, 
  Exclusions -> {2}, 
  ExclusionsStyle -> {None, Directive[Red, PointSize[.02]]}]

One way to also show the "dangling" point would be to combine plots:

Show[
  {Plot[f[x], {x, -1, 4}, Exclusions -> {2}, ExclusionsStyle -> {None, Directive[White, PointSize[.01]]}], 
   DiscretePlot[f[x], {x, 2, 2}, Filling -> None]}]

Obviously this doesn't lend itself to automation for arbitrary piecewise functions. For that, maybe look at the link provided in the comments above.

$\endgroup$
1
  • $\begingroup$ Thanks man very usefull $\endgroup$ Commented Jun 14, 2022 at 9:36

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.