6
$\begingroup$

Plotting a function in log-scale is a very common way to "compress" a function that grows too fast. What I want to do is to use a different function to compress a plot by. For example, I would like to scale the Y-Axis by a function I call the "bilateral logarithm" which is given by

BLog[x_] = Sign[x] Log2[Abs[x] + 1];

This function is nice because it is asymptotic to -Log2(-x) as x approaches -inf, Log2(x) as x approaches +inf, and BLog(-1)=-1, BLog(0)=0, BLog(1)=1. And all of this always holds for nested Blog(Blog(...)).

In summary, for a log-scale plot, the distances on the y-axis are proportional to Log(y), and I want to make it proportional to BLog(y). How do I make it happen?

edit: the inverse of this function is

Sign[x] (2^Abs[x] - 1)
$\endgroup$

2 Answers 2

5
$\begingroup$
$Version

(* "13.3.0 for Mac OS X ARM (64-bit) (June 3, 2023)" *)

Clear["Global`*"]

BLog[x_] = Sign[x] Log2[Abs[x] + 1];

Plot[BLog[x], {x, -5, 5}]

enter image description here

The inverse is

ParametricPlot[{BLog[x], x}, {x, -5, 5}, AspectRatio -> GoldenRatio]

enter image description here

Unfortunately, InverseFunction doesn't work well

Plot[InverseFunction[BLog][x], {x, -3, 3}]

enter image description here

Solving for the inverses

Assuming[y > 0, SolveValues[{y == BLog[x], x >= 0}, x][[1]] // Simplify]

(* -1 + 2^y *)

Assuming[y < 0, SolveValues[{y == BLog[x], x < 0}, x][[1]] // Simplify]

(* 1 - 2^-y *)

Consequently, use

invBLog[x_] = -Sign[x] + Sign[x] 2^(x Sign[x]) // Simplify

(* (-1 + 2^(x Sign[x])) Sign[x] *)

EDIT:

invBLog[x_] = FullSimplify[invBLog[x], x ∈ Reals]

(* (-1 + 2^Abs[x]) Sign[x] *)

Comparing with ParametricPlot

Show[
 ParametricPlot[{BLog[x], x}, {x, -5, 5}, AspectRatio -> GoldenRatio],
 Plot[invBLog[x], {x, -3, 3}, PlotStyle -> Directive[Red, Dashed]]]

enter image description here

An example of its use

Plot[x^3*Exp[x], {x, -10, 10}, Axes -> True,
 ScalingFunctions -> {None, {BLog, invBLog}}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks. Turns out it is possible to invert BLog also using Sign[] function IBLog[x_]=Sign[x] (2^Abs[x] - 1). Why does ScalingFunctions -> {None, IBLog} not work? Why do I need to do {BLog,IBLog} ? $\endgroup$ Jul 23 at 1:15
  • $\begingroup$ For a custom scaling function you have to provide both the scaling function and its inverse. See the documentation. $\endgroup$
    – Bob Hanlon
    Jul 23 at 1:48
8
$\begingroup$

You may use the parameter "ScalingFunctions". However, note that for this you need a function and its inverse. It will create some warning because the iinverse may be multivalued. However this is not the case for BLog. Here is an example. Without scaling function:

Plot[Exp[x], {x, 0, 10}]

enter image description here

And with BLog scaling function:

BLog[x_] = (Log[1 + Abs[x]] Sign[x])/Log[2];
Plot[Exp[x], {x, 0, 10}, Axes -> true, 
 ScalingFunctions -> {None, {BLog, InverseFunction[BLog]}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.