So, you have an arbitrary value of V
, and you know that 0 <= V
<= Vmax
. You want to calculate the x-coordinate of a pixel, name it X
, where your βscreenβ has x-coordinates from 0 to Xmax
. As you say, to do this in the βnormalβ way, you would do
X = Xmax * V / Vmax V = Vmax * X / Xmax
I like to think about it, as if I first normalize the value to lie between 0 and 1, calculating V / Vmax
, and then I multiply that value by a maximum to get a value from 0 to this maximum.
To do the same logarithmically, you will need a different lower limit for the value of V
If V is always <= 0, you get a ValueError
. So, let's say 0 < Vmin
<= V
<= Vmax
. Then you need to figure out which logarithm to use, since there are infinitely many of them. Usually there are three, those with a base of 2, e and 10, which leads to the X axis, which looks like this:
------|------|------|------|---- ------|------|------|------|---- 2^-1 2^0 2^1 2^2 == 0.5 1 2 4 ------|------|------|------|---- ------|------|------|------|---- e^-1 e^0 e^1 e^2 == 0.4 1 2.7 7.4 ------|------|------|------|---- ------|------|------|------|---- 10^-1 10^0 10^1 10^2 == 0.1 1 10 100
So, in principle, if we can get exponents from expressions to the left, we can use the same principle as above to get a value from 0 to Xmax
, and this, of course, is where the journal goes. Assuming you are using base b
, you can use these expressions to convert back and forth:
from math import log logmax = log(Vmax / Vmin, b) X = Xmax * log(V / Vmin, b) / logmax V = Vmin * b ** (logmax * X / Xmax)
This is almost the same way of thinking, except that you need to first make sure that log(somevalue, b)
will provide you with a non-negative value. You do this by dividing by Vmin
inside the log
function. Now you can divide by the maximum value that the expression can give, which, of course, is log(Vmax / Vmin, b)
, and you will get a value from 0 to 1, as before.
In another way, we first need to normalize ( X / Xmax
), and then scale again ( * logmax
) to the maximum value expected using the inverse functional. By the way, the opposite is to raise b
to a certain value. Now, if X
is 0, b ** (logmax * X / Xmax)
will be 1, so to get the correct lower limit, multiply by Vmin
. Or, to put it another way, since the first thing we did in a different way was to divide by Vmin
, we need to multiply by Vmin
as the last thing we are doing now.
To "increase" the "right side" of the equation, all you have to do is switch the equations, so you increase the speed from V
to X
and move on to the logarithm going the other way. In principle, this is so. Because you also need to do something with the fact that X
may be 0:
logmax = log(Xmax + 1, b) X = b ** (logmax * (V - Vmin) / (Vmax - Vmin)) - 1 V = (Vmax - Vmin) * log(X + 1, b) / logmax + Vmin