gyli / PyWaffle

🧇 Make Waffle Charts in Python.
MIT License
578 stars 105 forks source link

Fractional blocks #26

Open riley-x opened 2 years ago

riley-x commented 2 years ago

Is there a way to enable fractional blocks, so that there is no rounding? I'm especially running into issues where the rounding causes the total number of blocks to fluctuate, as in the example below. Both datasets total to 87.46 but the top plot has an extra block. It'd be great if the last block could have fractional size, and if the intermediate blocks could have split colors.

output

Code to reproduce:

plot1 = {'Net income': 18.46, 'Income tax': 1.64, 'MG&A': 7.52, 'R&D': 15.3, 'Cost of sales': 44.54}
plot2 = {'Misc income': 1.2, 'Revenue': 86.26}
fig = plt.figure(
    FigureClass=Waffle,
    plots={
        311: {'values':plot1},
        312: {'values':plot2}
    },
    rows=5,
    figsize=(9, 7),
    legend={'loc': 'upper left', 'bbox_to_anchor': (1.1, 1)},
    block_arranging_style='snake',
)
gyli commented 2 years ago

Hi @riley-x , thank you for submitting this feature. I believe it's a cool feature and also quite feasible. My only concern is it might require some trick to support fractional icon, but it could be added after the fractional blocks implementation anyways I guess. Stay tuned!