Draw a histogram with Python

Source: Internet
Author: User

Calculation frequency:

Given a sequence T:

hist = {}

For x in T:

HIST[X] = Hist.get (x,0) +1

The result is a dictionary that maps the value to its frequency. Divide it by N to convert the frequency into frequencies, which is called normalization:

n = float (len (t))

PMF = {}

For X, freq in Hist.items ():

PMF[X] = freq/n

To draw a histogram:

Vals, Freqs = Hist. Render ()

rectangles = Pyplot.bar (Vals, Freqs)

Pyplot.show ()

To draw the probability mass function:

Using a histogram, you can use Pyplot.bar or myplot.hist. If the values in the PMF are not many, the histogram is more appropriate

Using a line chart, you can use Pyplot.plot or MYPLOT.PMF. If the values in the PMF are larger and smoother, the line chart is more appropriate.

* Percent Variance Chart

Visual display of the two sets of data distribution differences, see the textbook.

From statistical thinking-Programmer's mathematical probability statistics p15-p23

Draw a histogram with Python

Related Article

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.