Use fixed exponent in scientific notation

Format it yourself (see Format Specification Mini-Language): for ix in [.02e9, .2e9, 2e9, 20e9, 200e9, 2000e9]: print(‘{:.3e} => {:0=8.3f}e9’.format(ix, ix / 1e9)) Output 2.000e+07 => 0000.020e9 2.000e+08 => 0000.200e9 2.000e+09 => 0002.000e9 2.000e+10 => 0020.000e9 2.000e+11 => 0200.000e9 2.000e+12 => 2000.000e9 Explanation {:0=8.3f} means “zero-pad, pad between the sign and the number, total field width … Read more

Scientific notation colorbar in matplotlib

You could use colorbar‘s format parameter: import matplotlib.pyplot as plt import numpy as np import matplotlib.ticker as ticker img = np.random.randn(300,300) myplot = plt.imshow(img) def fmt(x, pos): a, b = ‘{:.2e}’.format(x).split(‘e’) b = int(b) return r’${} \times 10^{{{}}}$’.format(a, b) plt.colorbar(myplot, format=ticker.FuncFormatter(fmt)) plt.show()