The above is showing how to draw a waffle chart with a Dictionary. It's also possible to draw with aDataFrame. Here is an example, let's use the embedded dataset called "mpg".
import seaborn as sns
mpg = sns.load_dataset('mpg')
Let's make a graph based on the "cylinders" variable. Firstly, we need to group by it and calculate the "counts". Then pass it to the figure.
df_cyl = mpg.groupby('cylinders').size().reset_index(name='counts_cyl')
fig = plt.figure(figsize = (14,6),
FigureClass=Waffle,
rows = 10,
values= df_cyl['counts_cyl'],
labels = ["{1}".format(n[0], n[1]) for n in df_cyl[['cylinders', 'counts_cyl']].itertuples()],
legend = {'loc': 'upper left', 'bbox_to_anchor': (1.05, 1), 'fontsize': 12, 'title':'cylinders'},
title = {'label': 'Vehicles by Cyl', 'loc': 'center', 'fontsize':18},
colors = ('#EC2272','yellow','#5ac9ff','#76ecbe','#fd5f00'))
Similarly, we can make a graph based on the "origin" variable.
df_origin = mpg.groupby('origin').size().reset_index(name='counts_origin')
n_categories = df_origin.shape[0]
fig = plt.figure(figsize = (14,6),
FigureClass=Waffle,
rows = 10,
values= df_origin['counts_origin'],
labels = ["{1}".format(n[0], n[1]) for n in df_origin[['origin', 'counts_origin']].itertuples()],
legend = {'loc': 'upper left', 'bbox_to_anchor': (1.05, 1), 'fontsize': 12, 'title':'cylinders'},
title = {'label': 'Vehicles by origin', 'loc': 'center', 'fontsize':18},
colors = ('yellow','#5ac9ff','#fd5f00'))