7

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

1 Answers1

7

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.

lericr
  • 27,668
  • 1
  • 18
  • 64