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()

Prevent scientific notation in ostream when using

To set formatting of floating variables you can use a combination of setprecision(n), showpoint and fixed. In order to use parameterized stream manipulators like setprecision(n) you will have to include the iomanip library: #include <iomanip> setprecision(n): will constrain the floating-output to n places, and once you set it, it is set until you explicitly unset … Read more

Parsing scientific notation sensibly?

Google on “scientific notation regexp” shows a number of matches, including this one (don’t use it!!!!) which uses *** warning: questionable *** /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ which includes cases such as -.5e7 and +00000e33 (both of which you may not want to allow). Instead, I would highly recommend you use the syntax on Doug Crockford’s JSON website which … Read more

Display a decimal in scientific notation

from decimal import Decimal ‘%.2E’ % Decimal(‘40800000000.00000000000000’) # returns ‘4.08E+10′ In your ‘40800000000.00000000000000’ there are many more significant zeros that have the same meaning as any other digit. That’s why you have to tell explicitly where you want to stop. If you want to remove all trailing zeros automatically, you can try: def format_e(n): a=”%E” … Read more