Skip to content

Commit

Permalink
Fix centering when dropping zeros (#23)
Browse files Browse the repository at this point in the history
When data was being plotted using a scale that included zeros
(e.g., raw5_0, raw7_0, agree5_0)
and those zeros were being dropped with drop_zeros=True,
the resulting plot was centered to the right of the middle value,
rather than in the middle of it.
(See screenshot in issue.)

The cause of this was that the code dropped the zero counts from the DataFrame
before plotting it, resulting in a dataset that had only 5 (or 7) scale values.
But the original scale was being passed in to the plotting function---
and it had one extra value (the zero). That scale was even-sized,
so the code assumed that there was no middle value, and the cut-off should be
between the two middle scale values.

This commit fixes this issue by removing the no-longer-present "0" value
from the scale before passing it to the plotting function
(but only if drop_zeros has been invoked).
  • Loading branch information
nmalkin committed Nov 24, 2021
1 parent 0a8802c commit 433a224
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plot_likert/plot_likert.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ def plot_likert(
else:
counts = likert_counts(df_fixed, format_scale, label_max_width, drop_zeros)

if drop_zeros:
plot_scale = plot_scale[1:]

return plot_counts(
counts,
plot_scale,
Expand Down

0 comments on commit 433a224

Please sign in to comment.