Convert Linear scale to Logarithmic

Notation As is the convention both in mathematics and programming, the “log” function is taken to be base-e. The “exp” function is the exponential function. Remember that these functions are inverses we take the functions as: exp : ℝ → ℝ+, and log : ℝ+ → ℝ. Solution You’re just solving a simple equation here: … Read more

Logarithmic y-axis bins in python

try plt.yscale(‘log’, nonposy=’clip’) http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.yscale The issue is with the bottom of bars being at y=0 and the default is to mask out in-valid points (log(0) -> undefined) when doing the log transformation (there was discussion of changing this, but I don’t remember which way it went) so when it tries to draw the rectangles for … Read more

Logarithmic slider

You can use a function like this: function logslider(position) { // position will be between 0 and 100 var minp = 0; var maxp = 100; // The result should be between 100 an 10000000 var minv = Math.log(100); var maxv = Math.log(10000000); // calculate adjustment factor var scale = (maxv-minv) / (maxp-minp); return Math.exp(minv … Read more

Why does math.log result in ValueError: math domain error?

Your code is doing a log of a number that is less than or equal to zero. That’s mathematically undefined, so Python’s log function raises an exception. Here’s an example: >>> from math import log >>> log(-1) Traceback (most recent call last): File “<pyshell#59>”, line 1, in <module> log(-1) ValueError: math domain error Without knowing … Read more

Fast fixed point pow, log, exp and sqrt

A very simple solution is to use a decent table-driven approximation. You don’t actually need a lot of data if you reduce your inputs correctly. exp(a)==exp(a/2)*exp(a/2), which means you really only need to calculate exp(x) for 1 < x < 2. Over that range, a runga-kutta approximation would give reasonable results with ~16 entries IIRC. … Read more

How can I specify the base for Math.log() in JavaScript?

“Change of Base” Formula / Identity The numerical value for logarithm to the base 10 can be calculated with the following identity. Since Math.log(x) in JavaScript returns the natural logarithm of x (same as ln(x)), for base 10 you can divide by Math.log(10) (same as ln(10)): function log10(val) { return Math.log(val) / Math.LN10; } Math.LN10 … Read more

Plot logarithmic axes

You can use the Axes.set_yscale method. That allows you to change the scale after the Axes object is created. That would also allow you to build a control to let the user pick the scale if you needed to. The relevant line to add is: ax.set_yscale(‘log’) You can use ‘linear’ to switch back to a … Read more

What is the difference between ‘log’ and ‘symlog’?

I finally found some time to do some experiments in order to understand the difference between them. Here’s what I discovered: log only allows positive values, and lets you choose how to handle negative ones (mask or clip). symlog means symmetrical log, and allows positive and negative values. symlog allows to set a range around … Read more