Figure and Axis Manipulation#

Update plot with returned Figure and Axes#

You are free to modify the figure generated by Waffle class. You may get all axes in the figure through property Figure.axes, and modify them through the list.

For example, if you would like to remove the auto-generated legend, and save the figure into a file, you can update the axis through axes property and then call savefig() with the returned figure:

fig = plt.figure(
    FigureClass=Waffle,
    rows=5,
    columns=10,
    values={'Cat1': 30, 'Cat2': 16, 'Cat3': 4},
)

# Remove legend
fig.axes[0].get_legend().remove()

# Save the figure into a file
fig.savefig("my_plot.png")

Make Waffle on Existed Axis#

Sometimes you might have figure and axis created already, and you would like to plot waffle chart on top of it, without creating a new figure. In this case, you may use Waffle.make_waffle() function, which accepts axis ax and other arguments available in Waffle.

NOTE: Waffle.make_waffle() is a classmethod, and you should call it without creating a new Waffle instance.

NOTE: The only argument that is available in Waffle but unsupported in Waffle.make_waffle() is plots, since it only accept one axis. Thus, this function can only generate waffle chart in a single plot.

Below is an example showing that you may create and modify the figure and axis first, and then pass the axis to Waffle.make_waffle() for waffle chart plotting.

fig = plt.figure()
ax = fig.add_subplot(111)

# Modify existed axis
ax.set_title("Axis Title")
ax.set_aspect(aspect="equal")

Waffle.make_waffle(
    ax=ax,  # pass axis to make_waffle
    rows=5, 
    columns=10, 
    values=[30, 16, 4], 
    title={"label": "Waffle Title", "loc": "left"}
)
With list values