Closed
Description
Problem
Sometimes, I keep my data in a dictionary, like so:
data = {
"Group A": [1, 1, 1, 2, 2, 3, 3, 3, 3],
"Group B": [1, 2, 2, 2, 2, 3, 3],
}
plt.hist(data.values(), histtype="barstacked", bins=np.arange(1, 5), label=data.keys())
plt.legend()
The legend here does not behave as hoped: only one label shows up (dict_keys(["Group A", "Group B"])). It would be nice if iterators like dict_keys worked in this context, since for instance they work in plt.pie()
's labels=
kwarg, and since the dict's .values()
works fine as the main argument to plt.hist()
here. Still, calling list()
is an easy workaround.
Proposed solution
No response