3.10 Waffle Chart
A waffle chart shows progress towards a target or a completion percentage. There is a grid of small cells, of which colored cells represent the data.
A chart can consist of one category or several categories. Multiple waffle charts can be put together to show a comparison between different charts.
We can use PyWaffle to plot fancy waffle charts.
Installation
pip install pywaffleExample
Let's create a dictionary (simple key-value structure) that includes randomly German Parties information.
# This is randomly made up!
data = {'CDU': 45,'SPD': 34,'Die Linke': 10,'Die GrĂ¼nen': 7, 'others': 4}import matplotlib.pyplot as plt
from pywaffle import Wafflefig = plt.figure(figsize = (14,6),
FigureClass=Waffle,
rows = 5,
values = data,
colors = ('#EC2272','yellow','#5ac9ff','#76ecbe','#fd5f00'),
title ={'label': 'Politische Parteien in Deutschland','loc':'left'},
labels = ["{0}({1}%)".format(k,v) for k,v in data.items()],
legend = {'loc': 'lower left', 'bbox_to_anchor': (0, -0.4), 'fontsize': 14, 'ncol': len(data)},
starting_location = 'NW')
Also, we can add aiconparameter to make it more attractive.

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".

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.

Similarly, we can make a graph based on the "origin" variable.

Last updated
Was this helpful?