python - How to set significant figures in pyplot annotation -
p-values , d-values k-s test need displayed on pylot histogram. thankfully, p-values low, low display 0.0
when use round
. tried numpy.set_printoptions(precision=3)
limit significant digits thousands place, changed output printing interpreter, , not graph.
ks_d, ks_p = ks_2samp(cntrl, test) ks_summ = "k-s d-value = {}\nk-s p-value = {}".format(round(ks_d, 3), round(ks_p, 3)) pyplot.annotate(ks_summ, xy=(0.70, 0.75), xycoords='axes fraction')
so how can display 1.2228387401e-24
(<class 'numpy.float64'>
) 1.223e-24
in graph annotation?
you need modify line
ks_summ = "k-s d-value = {}\nk-s p-value = {}".format(round(ks_d, 3), round(ks_p, 3))
to read
ks_summ = "k-s d-value = {}\nk-s p-value = {:.3e}".format(round(ks_d, 3), ks_p)
the {:.3e}
format means 3 decimal places exponential notation. , since rounding 3 decimal places in included in formatting notation, can drop code round ks_p
. example:
>>> ks_p = 1.2228387401e-24 >>> '{:.3e}'.format(ks_p) '1.223e-24'
finally, note can apply string format ks_d
, well. {:.3f}
may trick (i.e. 3 decimal place rounding).
>>> ks_d = 0.38210101 >>> '{:.3f}'.format(ks_d) '0.382'
Comments
Post a Comment