[Math] How to make a good “infinity plot”

graphing-functionsinfinity

This is what I mean (note the labels in the x axis):

infinity plot

The reason I'm looking at this problem is because I've always felt something was not right with truncated plots (e.g. of the exponential function, or functions with asymptotes) where the curve tends to infinity in one (or both) of the axes. I think it would be nice to have a plot that could contain the full range of a function, from $-\infty$ to $\infty$.

A log-log plot where the scale doesn't increase monotonically, but instead is symmetric about the origin, is close to a solution, and it can be obtained, for example, with matplotlib's "symlog" scaling option. However, such plots still need to be truncated somewhere. Ideally, to map an infinite range to a finite plot length, a sigmoid function is needed.

I could find a couple examples of this in practice, namely here and here (where I took the above image from).

At least the first of those uses the arctangent function to do the sigmoid scaling, but I wondered if there was a particular sigmoid function that is special, the same way the exponential function is the natural exponential curve. I didn't know exactly how to evaluate that, so I looked at these options and picked the one with the simplest mathematical representation: $\frac{x}{|x|+1}$.

Since the scaling was applied to both the x and y axes, this resulted in a nice plot for $f(x)=x$, as expected:

plot of y=x

but the plot for $f(x)=x^2$ wasn't as alike the original one near the extremes:
plot of y=sqrt(x)

and particularly the plot for $f(x)=e^x$ had a peculiar shape I wished was closer to the original (i.e. plotted in a linear scale):

plot of y=exp(x)

It looks like the slope of the sigmoid function I chose eventually surpasses that of the exponential function, so instead of approaching infinity from the bottom (so we can see that $y$ grows faster than $x$), it approaches it from the left, making it look that at some point $x$ starts to grow faster than $y$.

I tried the other sigmoid functions mentioned in the image above, but they had the same effect, or worse, in the shape of the exponential. So my question is: is there a way to compress the infinite range of a function into a finite length of a plot that allows preserving the overall shape of the exponential function (and hopefully others too)?

Additionally, I'd appreciate if you could also tell me whether there is a "natural" sigmoid function, or at least what you would consider to be the best approximation of such a thing.

Best Answer

I suspect there is no natural sigmoid function that will "preserve" in some sense your original function $f$.

In all generality, you want to "squeeze" the real line ($\mathbb{R}$) into an (open) interval of the form $(x_1,x_2)$. Let's try to squeeze both the $x$-axis and the $y$-axis so that we may fit one graph into a rectangle. Let this rectangle be, for simplicity, $(-a,a)\times(-b,b)$ where $a$ and $b$ are positive.

Let $D$ be the domain of $f$ and $R$ be its codomain (for the sake of simplicity, let's think of $R$ as $\mathbb{R}$)

To squeeze the $x$-axis we really need a function $\varphi:\ (-a,a)\longrightarrow D$, so that when we graph $f\circ\varphi$ we'll need to see what that thing does only on the interval $(-a,a)$.

To squeeze also the $y$-axis, we need another function $\psi:R\longrightarrow(-b,b)$. The end result is then \begin{equation} \tilde{f}:=\psi\circ f\circ\varphi \end{equation} Its graph will be contained in the rectangle $(-a,a)\times(-b,b)$.

The tricky part, as you pointed out, is finding the "right" sigmoid function(s). One can try various cocktails. If $D=R=\mathbb{R}$ for instance, one could take \begin{equation} \varphi(x):=k\tan\left(\frac{\pi}{2a}x\right)\qquad\psi(x):=\frac{2b}{\pi}\arctan(x/k) \end{equation} to do the job. Varying the parameter $k$ allows for trying to "match" the original function (for biggish $k$). It really depends on what characteristics of $f$ you want to study.

[EDIT: I personally like viewing functions "wrapped" on a sphere- but it's only an aesthetic approach. Here i posed a question about it.]