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 Answer 1


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:

  {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.

  • $\begingroup$ Thanks man very usefull $\endgroup$ Jun 14 at 9:36

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.