def get_cdf (numlist):p rint "Total number of numlist%d"%len (numlist) Numarray = Np.asarray (numlist) dx =. 01bins_array = NP. Arange ( -0.5,1.5,DX) hist, bin_edges = Np.histogram (Numarray, Bins=bins_array, normed=false) CDF = Np.cumsum (hist) CDF = Cdf/float (Hist.sum ()) Bins_list = Bins_array[1:]return (bins_list, CDF)
Toss for a long time, before writing a painting histogram map code, but found that if you want to draw two list words, there will be problems, their subscript can not be unified, and the previous code also has a problem, explained that if the list of elements are 0-1 decimal between, it is very easy to get up and down rounding, becomes 1, 0, and then the effect of drawing out is not normalized.
Http://stackoverflow.com/questions/9378420/how-to-plot-cdf-in-matplotlib-in-python This answer is to enlighten me how to solve the problem. thank him.
Today, in order to draw two pictures of the case, I found a lot of information, and finally sorted out a. Recorded.
There are a few questions to note
1.cdf/float (Hist.sum ()) Here must float otherwise, out of all is 0, because it is here to ask for the frequency of the decimal, if not added float, it becomes 0.
2.bins_list = bins_array[1:] This needs to be taken from 1, because after Cumsum, an element is missing because the first element has a value of 0, which is automatically omitted. In addition Bins_array can be used to convert directly to array. This is quite an accident. This one is missing a number, can refer to this answer Http://stackoverflow.com/questions/15697350/binning-frequency-distribution-in-python
3.histogram,normed I set here is false, because I set to true, statistics is the probability, has been wrong, I did not understand his probability is how to calculate. False is the frequency. Let me know if anyone understands the trouble of true. Thank you
The drawing normalization of Python histogram