Value Scaling and Auto-sizing#
Value Scaling#
It is a common case that the chart size does not equal to the total number of values. Then the values have to be scaled to fit the chart size.
Change argument rounding_rule to set a preferred rounding rule when scaling. It accepts floor or ceil or nearest.
NOTE: When
rounding_ruleisceilornearest, sum of scaled values might be greater than chart size. If so, the blocks of last category would not be shown completely in the chart. Therefore, althoughnearestis the default rounding rule,flooris actually the most consistent rule as it avoids the block overflowing.
In the following example, values are scaled to 24, 23, 1 as block numbers with rounding_rule=floor.
plt.figure(
FigureClass=Waffle,
rows=5,
columns=10,
values=[48, 46, 3],
rounding_rule='floor'
)
Auto-sizing#
If you would like to avoid values scaling, pass an integer to either one of rows or columns parameter only. Then the absolute number of values would be used as block number directly and the other parameter would be calculated automatically.
In the following example, we set rows=5, values=[48, 46, 3] and leave columns empty. Then the block numbers would be the same to values. Since the sum of values is 97, the column number has to be 20 to fit all blocks.
plt.figure(
FigureClass=Waffle,
rows=5,
values=[48, 46, 3]
)
Fractional Blocks#
Set rounding_rule='float' to stop rounding values altogether. A category that ends part way
through a block fills only that fraction of it, and a block that contains a boundary between two
categories is split between their colors.
plt.figure(
FigureClass=Waffle,
rows=5,
values={'Net income': 18.46, 'Income tax': 1.64, 'MG&A': 7.52, 'R&D': 15.3, 'Cost of sales': 44.54},
rounding_rule='float',
block_arranging_style='snake',
)
The useful consequence is that the number of blocks depends only on the total of the values.
With rounding, two datasets that sum to the same number could produce charts of different sizes,
because each value is rounded independently and the errors need not cancel. With
rounding_rule='float' they are always the same size, which matters when charts are compared
side by side or animated over time.
Note
rounding_rule='float' draws partially filled rectangles, so it cannot be combined with icons
or characters — a glyph cannot be partially filled. Passing them together raises a ValueError.