Skip to content
Visual AnalyticsMatplotlib and Seaborn

Formulas for this chapter

Grouped bar offsets

position of series k = x + (k - (m + 1) / 2) * width, painted width = m * width

When several series share each category slot. Keep m x width below 1 so the groups stay separated, and restore the category names with plt.xticks.

x
Category centres, usually np.arange(number of categories)
m
Number of series (bars per group)
k
Which series, counting from 1
width
Bar width in x-axis units; Matplotlib's default is 0.8

Histogram bin count from np.arange

edges = np.arange(start, stop, step); bins = number of edges - 1 = ceil((stop - start) / step) - 1

Whenever a histogram question gives bin edges rather than a bin count. Remember np.arange excludes its stop value, so push stop past the last edge you want.

start
First bin edge, included
stop
Excluded upper limit
step
Bin width

Pie slice share and angle

share = value / total; percent printed by autopct = 100 * share; angle = 360 * share

For any pie-chart question, and for the argument against pie charts: convert two slices to degrees and show how close they are.

value
One category's size, as passed to plt.pie
total
Sum of every value in the list
autopct
Format string, e.g. '%1.1f%%', that prints the percentage
Step 3 of 26
The real wordsTheory

What Matplotlib is

MatplotlibA plotting library with the NumPy numerical mathematics extension. It draws 2-D and 3-D plots and was introduced by John Hunter in 2002.

The plot families the deck names: linear, histogram (hist), scatter, box, bar, pie, stem, fill_between or area, and step.

Nine families, one for every shape you met in the chart-selection chapter. NumPy is the part that does arithmetic on whole lists at once.