The drawing normalization of Python histogram

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.