PyWaffle Documentation
NOTE: Parameters which are passed outside of plots would be applied to all subplots, if they are not
specified in plots. Otherwise, settings in plots have higher priority.
fig = plt.figure(
FigureClass=Waffle,
plots={
311: {
'values': data['Factory A'] / 1000, # Convert actual number to a reasonable␣
˓→block number
'labels': [f"{k} ({v})" for k, v in data['Factory A'].items()],
'legend': {'loc': 'upper left', 'bbox_to_anchor': (1.05, 1), 'fontsize': 8},
'title': {'label': 'Vehicle Production of Factory A', 'loc': 'left',
˓→'fontsize': 12}
},
312: {
'values': data['Factory B'] / 1000,
'labels': [f"{k} ({v})" for k, v in data['Factory B'].items()],
'legend': {'loc': 'upper left', 'bbox_to_anchor': (1.2, 1), 'fontsize': 8},
'title': {'label': 'Vehicle Production of Factory B', 'loc': 'left',
˓→'fontsize': 12}
},
313: {
'values': data['Factory C'] / 1000,
'labels': [f"{k} ({v})" for k, v in data['Factory C'].items()],
'legend': {'loc': 'upper left', 'bbox_to_anchor': (1.3, 1), 'fontsize': 8},
'title': {'label': 'Vehicle Production of Factory C', 'loc': 'left',
˓→'fontsize': 12}
},
},
rows=5, # Outside parameter applied to all subplots, same as below
cmap_name="Accent", # Change color with cmap
rounding_rule='ceil', # Change rounding rule, so value less than 1000 will still␣
˓→have at least 1 block
figsize=(5, 5)
)
fig.suptitle('Vehicle Production by Vehicle Type', fontsize=14, fontweight='bold')
fig.supxlabel('1 block = 1000 vehicles', fontsize=8, ha='right')
2.9 Adjust Figures
2.9.1 Figure Size, Background Color, DPI, etc.
Built-in parameters of matplotlib.pyplot.figure could be passed alone with Waffle as FigureClass and PyWaffle
parameters. Some of them are commonly used to adjust figure, like figsize, dpi, facecolor, tight_layout, etc.
Check matplotlib.pyplot.figure for the details.
In the following example, we change the background color of figure by passing color value to facecolor.
fig = plt.figure(
FigureClass=Waffle,
(continues on next page)
14 Chapter 2. Examples