Source
Adapted from my own handwritten and hand-typed notes from Year 1 to Year 3 of my EEE degree
Four standard plots show the distribution of one numeric variable.
Box Plot
A box plot draws the quartiles:
- the box runs from to , with a line at the median
- box length is the interquartile range
- whiskers reach to the furthest data point within and
- points beyond the whiskers are drawn separately as outliers
- each of the four parts (lower whisker, lower box, upper box, upper whisker) holds about 25% of the data
For Pokemon HP: , , so and the whisker limits are and . Any HP above 125 is plotted as an outlier.
Histogram
A histogram splits the range into bins and draws the count in each bin. It shows the shape of the distribution (peaks, skew, gaps).
Density Plot (KDE)
A kernel density estimate is a smooth curve version of the histogram. The area under it is 1.
Violin Plot
A violin plot is a box plot with a mirrored KDE on each side, so it shows the quartiles and the full shape together.
Code
import seaborn as sb
import matplotlib.pyplot as plt
f = plt.figure(figsize=(16, 4))
sb.boxplot(data=hp, orient='h')
f = plt.figure(figsize=(16, 4))
sb.histplot(data=hp) # older course code: sb.distplot(hp)
f = plt.figure(figsize=(16, 4))
sb.kdeplot(data=hp)
f = plt.figure(figsize=(16, 4))
sb.violinplot(data=hp, orient='h')When the histogram looks bell shaped, the spread can be read in standard deviations, see Normal Distribution and Z-Score.