8000 [ENH]: Iterables in grouped histogram labels · Issue #27954 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
8000
[ENH]: Iterables in grouped histogram labels #27954
Closed
@cwindolf

Description

@cwindolf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0