Exercise

# Cumulative Distribution Function from an image histogram

A histogram of a continuous random variable is sometimes called a *Probability Distribution Function* (or *PDF*).
The area under a PDF (a definite integral) is called a *Cumulative Distribution Function* (or *CDF*).
The CDF quantifies the probability of observing certain pixel intensities.

Your task here is to plot the PDF and CDF of pixel intensities from a grayscale image.
You will use the grayscale image of Hawkes Bay, New Zealand
(originally by Phillip Capper, modified by User:Konstable, via Wikimedia Commons, CC BY 2.0).
This time, the 2D array `image`

will be pre-loaded and pre-flattened into the 1D array `pixels`

for you.

- The histogram option
`cumulative=True`

permits viewing the CDF instead of the PDF. - Notice that
`plt.grid('off')`

switches off distracting grid lines. - The command
`plt.twinx()`

allows two plots to be overlayed sharing the x-axis but with different scales on the y-axis.

Instructions

**100 XP**

- First, use
`plt.hist()`

to plot the histogram of the 1-D array`pixels`

in the bottom subplot. - Use the histogram options
`bins=64`

,`range=(0,256)`

, and`normed=False`

. - Use the plotting options
`alpha=0.4`

and`color='red'`

to make the overlayed plots easier to see. - Second, use
`plt.twinx()`

to overlay plots with different vertical scales on a common horizontal axis. - Third, call
`plt.hist()`

again to overlay the CDF in the bottom subplot. - Use the histogram options
`bins=64`

,`range=(0,256)`

, and`normed=True`

. - This time, also use
`cumulative=True`

to compute and display the CDF. - Also, use
`alpha=0.4`

and`color='blue'`

to make the overlayed plots easier to see.