Non-linear axes for imshow in matplotlib

In my view, it is better to use pcolor and regular (non-converted) x and y values. pcolor gives you more flexibility and regular x and y axis are less confusing. import pylab as plt import numpy as np from matplotlib.colors import LogNorm from matplotlib.ticker import LogFormatterMathtext x=np.logspace(1, 3, 6) y=np.logspace(0, 2,3) X,Y=np.meshgrid(x,y) z = np.logspace(np.log10(10), … Read more

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

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

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

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

Logarithm for BigInteger

If you want to support arbitrarily big integers, it’s not safe to just do Math.log(bigInteger.doubleValue()); because this would fail if the argument exceeds the double range (about 2^1024 or 10^308, i.e. more than 300 decimal digits ). Here’s my own class that provides the methods double logBigInteger(BigInteger val); double logBigDecimal(BigDecimal val); BigDecimal expBig(double exponent); BigDecimal … 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