Waffle plot

mpl-visual-context
Author

Jae-Joon Lee

Published

March 5, 2025

Modified

March 5, 2025

Waffle plot

Let’s decorate waffle plot with matplotlib image effects.

Let’s start with a simple waffle plot, created using the pywaffle package.

import matplotlib.pyplot as plt
from pywaffle import Waffle

fig, ax = plt.subplots(1, 1, num=1, clear=True)

ax.set_aspect(aspect="equal")

Waffle.make_waffle(
    ax=ax,
    rows=5,
    columns=10,
    values=[30, 16, 4],
    title={"label": "Waffle", "loc": "left"}
)

Let’s apply some imageeffect.

from mpl_visual_context.patheffects import ImageEffect
from mpl_visual_context.image_effect import Pad, LightSourceSharp

pe_waffle1 = ImageEffect(Pad(10) | LightSourceSharp(dist_max=7, azdeg=215, altdeg=70,
                                                    fraction=0.97,
                                                    vert_exag=0.2,
                                                    ))

for p in ax.patches:
    p.set_path_effects([pe_waffle1])

Another effect.

from mpl_visual_context.image_effect import LightSource

pe_waffle2 = ImageEffect(Pad(10) | LightSource(azdeg=215))

for p in ax.patches:
    p.set_path_effects([pe_waffle2])