Consider the plot of this discontinuous function:


plot of a discontinuous function



  • $\begingroup$ These are amazing answers; thanks so much everyone! $\endgroup$ – dreeves Dec 8 '10 at 6:54
  • $\begingroup$ see here for Mathematica Q&A: Excluding Points from Plots (from Wolfram) $\endgroup$ – user1066 Mar 15 '11 at 10:28
  • $\begingroup$ Is this the community's first question? $\endgroup$ – LCarvalho Dec 23 '17 at 7:18


      Exclusions ->

(* Testing *)

pl[f, {0, 5}];
pl[Tan, {0, 2 Pi}]

Mathematica graphics



(*Function Definition*)

flist = {
   1/Sin@# + 1 &,


alt text

Edit 2






Edit 3

Found a way with a discrete derivative, a tricky thing.

Like this:

(*Function Definition*)

Note two issues:

  • $\begingroup$ Okay, simple question: why does the addition of f[u]==1 help? Exclusions -> True, alone, does not work, so why does the addition of the function work? I'm honestly confused. BTW: +1, simple and clever. $\endgroup$ – rcollyer Dec 8 '10 at 12:28
  • $\begingroup$ Wow, this seems like a definitive improvement to Plot itself. My only reservation about it is what happens when the function is not invertible... $\endgroup$ – dreeves Dec 8 '10 at 15:37
  • 1
    $\begingroup$ @dreeves I am not using InverseFunction anymore. And trig functions are not invertible ... I am still trying to find a counterexample where this doesn't work, since I am not blind-confident about the method. $\endgroup$ – Dr. belisarius Dec 8 '10 at 20:10
  • 1
    $\begingroup$ @rcollyer I was experimenting a lot. I really do not understand why this work, but I am still not able to find a counter-example. $\endgroup$ – Dr. belisarius Dec 8 '10 at 20:12
  • $\begingroup$ @belisarius, per edit 2, changed the exclusion to f[u]==u and it only excluded the second and third discontinuity. So, you're definitely on to something. My thinking is that you'll need to know a little about the domain/range of your function in order to properly set up the exclusions, i.e. plot it without the exclusions first. $\endgroup$ – rcollyer Dec 9 '10 at 4:36

The answer is Exclusions as follows:

alt text




and compare the numerical derivatives on both sides of each point




  • $\begingroup$ Here is another nice way to find the discontinuities forums.wolfram.com/mathgroup/archive/2009/Aug/msg00387.html. The first function def lacks the "==" sign before the "z" $\endgroup$ – Dr. belisarius Dec 8 '10 at 6:40
  • $\begingroup$ It should be noted that Select is calculating something close to the second derivative (en.wikipedia.org/wiki/…), and it may be simpler to think of it in those terms. $\endgroup$ – rcollyer Dec 8 '10 at 12:23
  • $\begingroup$ Can something like this be adapted for a ListPlot, where you have discrete samples of the function? I want to exclude points that are near a discontinuity (because the samples here are very unreliable) $\endgroup$ – becko Mar 16 '17 at 0:06
  • 1
    $\begingroup$ @becko you'll have to mask them yourself. Although, I'd exchange the problematic points for Missing[] as ListPlot will produce something similar to Exclusions in that case. $\endgroup$ – rcollyer Mar 16 '17 at 15:00



Update: This code might have worked in earlier versions of Mathematica. As of version 11, it does not work anymore.

  • $\begingroup$ +1 One of those features I usually forget about ... $\endgroup$ – Dr. belisarius Dec 9 '10 at 18:35
  • $\begingroup$ +1 I cannot recall seeing this before. $\endgroup$ – Mr.Wizard Mar 4 '11 at 9:37
  • $\begingroup$ Checking back,I found out about this in the following Mathmergency video. Not, as I thought, a Wolfram presentation. $\endgroup$ – user1066 Mar 4 '11 at 16:40
  • $\begingroup$ @Mr.Wizard Does this still work? On v11 I get a weird output: System`ProtoPlotDump`iPlot[Plot, System`ProtoPlotDump`obj$1974, f[x], {x, 0, 2, 3, 5}] $\endgroup$ – becko Mar 16 '17 at 0:08
  • $\begingroup$ @becko It fails in version 10.1 as well. Likely it was experimental syntax that was rejected. $\endgroup$ – Mr.Wizard Mar 16 '17 at 5:53

This works:




  • $\begingroup$ Thanks, good answer, though note the restriction that I don't want to modify the function f. $\endgroup$ – dreeves Dec 8 '10 at 0:49
  • $\begingroup$ Oops. rcollyer posted his answer while I added Exclusions to mine. :-) $\endgroup$ – Gustavo Delfino Dec 8 '10 at 0:54
  • $\begingroup$ @gdelfino: it took me a few moments to find it and generate the graphs. $\endgroup$ – rcollyer Dec 8 '10 at 0:56
  • $\begingroup$ @gdelfino, I was trying to imply that if it hadn't taken me that long, I would have posted it much sooner. But, it seems that I completely missed that point in my comment. $\endgroup$ – rcollyer Dec 8 '10 at 20:40
  • $\begingroup$ @rcollyer Thank's fine. It is incredible how fast people answer good questions in stackoverflow. $\endgroup$ – Gustavo Delfino Dec 9 '10 at 12:24



Maybe I am getting late here, but in Mathematica 11 (and perhaps earlier versions) the ExclusionsStyle option would do the job, also for arbitrary functions...

Plot[f[x], {x, 0, 5}, ExclusionsStyle -> None]

Another example that also works

f[x_] := Tan[x]
Plot[f[x], {x, 0, 2 \[Pi]}, ExclusionsStyle -> None, PlotRange -> {-20, 20}]

Your Answer

