matplotlib 入門 (12) nitta@tsuda.ac.jp

Chapter 12: Bar Graph (2)

12-1: Generate a normal distribution histogram and draw the lines of probability density his

    Axes.hist(x,
              bins=None,  # number of bin(class)
              range=None,  # lower and upper limits of class
              density=None,  # frequency if False, probability otherwise. 
                             #The return value is F (list of values, list of lower bounds, patch object)
              histtype='bar', # type of bar (bar/barstacked/step/stepfilled)
              align='mid',    # position of bar (left/mid/right)
              orientation='vertical', # bar orientation (horizontal/vertical)
              color=None,
              **kwargs   # specify the properties of Patch class
             )

Normal distribution probability density function

$\displaystyle f(x) = \frac{1}{\sqrt{2\pi \rho}} e^{\frac{(x - \mu)^2}{2 \sigma^2}} $
where $\mu$: the average, $\sigma^{2}$: the variance.

12-2: Bins of different widths are arranged side by side and automatically aggregated and plotted hist

An array of 10 numbers in ascending order

bins = [ 0, 20, 30, 40, 45, 50, 55, 60, 70, 100 ]
represents the next 10 bins.
     0 - 19
    20 - 29
    30 - 40
    40 - 44
    45 - 49
    50 - 54
    55 - 59
    60 - 69
    70 - 79
    80 - 99

12-3: Combine multiple data into one histogram

By increasing the number of bars drawn in the bin of the histogram, the distribution of multiple data can be combined into one graph.

12-4: Generate histogram of the cumulative frequency distribution (cumulative probability)

The cumulative frequency distribution can be expressed by adding the frequencies of the bins. Converts the cumulative frequency to cumulative probability and draws a histogram where the bars are stepped towards brobability 1 (100%).