You can see in such a function, there are some points in space in which the value of the function reaches infinity (Those empty areas in the on the x and y axis).


enter image description here

The infinity region can be things other than just some points. It may be a disk or a line that in any point of that region, the value is infinity.

ONLY those infinity areas are of my interest! How to visualize that? for example Mathematica colors any region which has infinity value, red.

Can anyone help me?


2 Answers 2


You can apply a sigmoid function before plotting. It maps the whole interval of real numbers onto [-1,1] interval. A suitable choice is $\tanh(x)$:

DensityPlot[Tanh[1/(x y)], {x, -5, 5}, {y, -5, 5}, MaxRecursion -> 5, 
 ColorFunction -> "LakeColors", PlotLegends -> Automatic, PlotRange -> {-1, 1}]

which generates:

enter image description here

  • $\begingroup$ This is a good way to remove those empty regions. But what I dreamed was, in the plot you pictured, two crossed red lines. Is there any way to achieve that? $\endgroup$
    – AHB
    Commented Aug 26, 2016 at 11:54
  • $\begingroup$ And! Will this sigmod function be dependable for any function inside it? Like dirac delta. $\endgroup$
    – AHB
    Commented Aug 26, 2016 at 11:55
  • $\begingroup$ It failed in 3D functions. :( $\endgroup$
    – AHB
    Commented Aug 26, 2016 at 12:07
  • $\begingroup$ @AHB I cannot test with DensityPlot3D because I have older version of MA. $\endgroup$
    – yarchik
    Commented Aug 26, 2016 at 12:44
  • $\begingroup$ @AHB Do you mean it fails for $\delta(\vec r)$ ? $\endgroup$
    – yarchik
    Commented Aug 26, 2016 at 14:16

Compactify the function with a coordinate transformation $$u=1/x$$ with such a transformation "$x\rightarrow\infty \Leftrightarrow u \rightarrow0$":

DensityPlot[u*v, {u, 1/-5, 1/5}, {v, 1/-5, 1/5},PlotLegends -> Automatic]

Which generates:

x*y density plot

This is a nice trick to work with infinity in numerics; the only downside is that the legend and the axes are in respect to the transformed coordinates, but with axis label this should be resolvable.

  • $\begingroup$ Are you sure you compactify this way? Where does zero go? $\endgroup$
    – yarchik
    Commented Aug 26, 2016 at 13:11
  • $\begingroup$ Yes you got me; "compactify" might be to strong: sure you get rid of one singularity at $\infty$ and get yourself a new one at $0$. But If your function does not have nulls in the region you are interested in it works. If you have $0$ and $\infty$ you have to use something else like you proposed but if you only have $\infty$ I think working with a coordinate transform like this one gives easier to interpret results: I mean if you look at the $\tanh[f]$ in that case those discontinuities on the axes are certanly an artifact of $\tanh$ and not a feature of $1/(xy)$. $\endgroup$
    – N0va
    Commented Aug 26, 2016 at 13:20
  • $\begingroup$ Sorry to be so pedantic, the discontinuities on the axes are also present in the original function. Fix for instance $y=y_0=1/c$. In this case we have f(x)=$c/x$. And this function is $-\infty$ at $x\rightarrow -0$ and $\infty$ for $x\rightarrow+0$. It is just a remark, each transformation has its strong and weak sides. $\endgroup$
    – yarchik
    Commented Aug 26, 2016 at 14:15

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.