Closed charlesbaynham closed 3 years ago
PS hope you don't mind all these little changes!
Quite the opposite, I really appreciate them! These are all things that have annoyed me but I haven't gotten around to fixing them. Thank you for taking the time to improve the experience for everyone!
Regarding this specific change, I think it's great — I'd definitely be happy to remove the "Legend" entry.
One question, though: when I run with this change, I get the following warning:
[…]/lib/python3.9/site-packages/pandas/plotting/_matplotlib/core.py:613: UserWarning: The handle <BarContainer object of 2 artists> has a label of '_padding_row' which cannot be automatically added to the legend.
ax.legend(handles, labels, loc="best", title=title)
(Matplotlib version 3.3.4)
Do you get the same warning?
Fortunately, I do think there's another option: per the guide, having the label be an empty string also hides it.
I made this change:
diff --git a/plot_likert/plot_likert.py b/plot_likert/plot_likert.py
index aa875e1..ebfe75b 100644
--- a/plot_likert/plot_likert.py
+++ b/plot_likert/plot_likert.py
@@ -62,7 +62,7 @@ def plot_counts(
padding_values = (middles - center).abs()
padded_counts = pd.concat([padding_values, counts], axis=1)
# hack to "hide" the label for the padding
- padded_counts = padded_counts.rename({0: "Legend"}, axis=1)
+ padded_counts = padded_counts.rename({0: ""}, axis=1)
…and it seems to have the desired effect, with no warning.
So maybe we can go with that?
Embarrassingly, yes I do, but it was swamped in the other output from the rest of my code so I hadn't noticed it. But yes, your solution makes a lot of sense! I'll add it into this PR
Great! Let's go with that approach, then. Thanks again!
Hide the "legend" padding box by marking it with a
_
for matplotlib to ignore (see http://blog.rtwilson.com/easily-hiding-items-from-the-legend-in-matplotlib/)PS hope you don't mind all these little changes!