Formatting of significant figures
For tables or numbers in plots it best practice to only give significant figures. These python functions can do the job automatically given a value and its uncertainty.
Consequently, this produces the following outpurts
In [6]: reduceToSignificantFigure(.123456, .1 )
Out[6]: (0.1, 0.1)
In [7]: reduceToSignificantFigure(.423456, .1 )
Out[7]: (0.4, 0.1)
In [8]: reduceToSignificantFigure(.153456, .1 )
Out[8]: (0.2, 0.1)
In [9]: reduceToSignificantFigure(1.45E-3, 3E-5 )
Out[9]: (0.00145, 3e-05)
In [10]: reduceToSignificantFigure(1.45E-3, 3E-4 )
Out[10]: (0.0014, 0.0003)
And to get strings with the correct numers of zeros
which produces
In [14]: print "%s +/- %s" % (formatError(1004.123456, 12.00100001 ))
1004 +/- 12
In [15]: print "%s +/- %s" % (formatError(.123456, .00100001 ))
0.123 +/- 0.001
The function is part of the matplotlibtools, a collection of helper functions and classes to work with matplotlib and numpy.