Search code examples
pythonmatplotlibwaffle-chart

How do I change the direction of a vertical Waffle?


I have this script that generates a Waffle of example date:

import matplotlib.pyplot as plt
from pywaffle import Waffle
values = [3, 8, 9, 13, 9, 4, 5, 9, 10, 7, 4, 1]
colors = ["#1D428A", "#5566A6", "#838DC2", "#B1B6DF", "#DEE1FC", "#FFFFFF"]
colors = colors + colors[::-1]
fig = plt.figure(
    FigureClass = Waffle,
    columns = 4,
    values = values[::-1],
    colors = colors,
    block_arranging_style = "snake",
    vertical = True)
plt.savefig("test1.png")

The result looks like this: https://i.sstatic.net/sTuGW.jpg. In short, I want the direction of the Waffle to be changed: instead of two squares in the first line and four in the last one, I want the opposite: four squares in the first line and two in the last one. How can I do this?


Solution

  • I am using it for the first time, but I think it is possible with the direction setting in the official reference.

    Where to Start First Block Use parameter starting_location to set the location of starting block. It accepts locations in string like NW, SW, NE and SE representing four corners. By default, it is SW, meaning PyWaffle starts drawing blocks from lower-left corner.

    Here is an example that start plotting from lower-right corner (SE).

    import matplotlib.pyplot as plt
    from pywaffle import Waffle
    values = [3, 8, 9, 13, 9, 4, 5, 9, 10, 7, 4, 1]
    colors = ["#1D428A", "#5566A6", "#838DC2", "#B1B6DF", "#DEE1FC", "#FFFFFF"]
    colors = colors + colors[::-1]
    fig = plt.figure(
        FigureClass = Waffle,
        columns=4,
        values = values[::-1],
        colors = colors,
        block_arranging_style = "snake",
        vertical = True,
        starting_location='NE'
        )
    plt.savefig("test1.png")
    

    enter image description here