plot_diff
plot_diff(
data,
label='feature',
difference='difference',
limits=None,
digits=2,
pos_colour=POSITIVE_COLOUR,
neg_colour=NEGATIVE_COLOUR,
title=None,
)Diverging bar chart of differences.
Plots a column of differences (e.g. from compare_values()) as a sorted, diverging horizontal bar chart: the standard “what improved, what slipped” change chart. Bars are sorted by the difference and drawn horizontally (largest gain at the top), green for positive and amber for negative changes, with signed value labels (+0.2 / -0.3) just outside each bar and a zero reference line. When limits is None the axis is made symmetric around zero from the data so gains and losses are visually comparable.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | pandas.DataFrame | A table with a label column and a difference column. | required |
| label | str | Category column. Default “feature”. | 'feature' |
| difference | str | Difference column. Default “difference”. | 'difference' |
| limits | list of float | Axis limits. None (default) chooses a symmetric range from the data. | None |
| digits | int | Decimal places for the value labels. Default 2. | 2 |
| pos_colour | str | Bar colours for positive and negative differences. | POSITIVE_COLOUR |
| neg_colour | str | Bar colours for positive and negative differences. | POSITIVE_COLOUR |
| title | str | Plot title. | None |
Returns
| Name | Type | Description |
|---|---|---|
| plotnine.ggplot | The chart. |
See Also
compare_values
Examples
>>> a = pd.DataFrame({"feature": ["price", "quality", "service"], "performance": [3.1, 4.2, 3.5]})
>>> b = pd.DataFrame({"feature": ["price", "quality", "service"], "performance": [2.8, 4.4, 3.9]})
>>> compare_values(b, a).pipe(plot_diff)