Skip to content

[Bug]: ValueError: The 'color' keyword argument must have one color per dataset #30857

Closed

Description

@gapplef

Bug summary

We can plot multiple lines in one color with plt.plot, but not with plt.hist.
I'm not sure if this considered as a bug, but I can't understand why hist force this requirement.

Code for reproduction

import matplotlib.pyplot as plt

data = [[0, 1, 2], [3, 4, 5]]

plt.plot(data, color='k')
plt.show()

plt.hist(data, color='k')

Actual outcome

plt.plot works as expected, but plt.hist get the following error

ValueError: The 'color' keyword argument must have one color per dataset, but 2 datasets and 1 colors were provided.

Expected outcome

Just plot the histograms in same color
What I want to achieve is
hist_prior
hist_post

Additional information

No response

Operating system

No response

Matplotlib Version

3.10.8

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Activity

  1. jkeo180 commented on Dec 15, 2025

    @jkeo180

    do you mind if i fork the code and see about fixing the problem?

  2. gapplef commented on Dec 15, 2025

    @gapplef
    ContributorAuthor

    @jkeo180 Sorry, but what do you mean by 'fork the code'? I provided the minimal reproducible example above.

  3. jkeo180 commented on Dec 15, 2025

    @jkeo180

    i'm sorry i should've been more clear. Did you want help fixing a bug?

  4. gapplef commented on Dec 15, 2025

    @gapplef
    ContributorAuthor

    Yeah, if this is not the intended behavior, I may have a look.

  5. story645 commented on Dec 15, 2025

    @story645
    Member

    @rcomer, does this get fixed w/ #30808?

  6. rcomer commented on Dec 15, 2025

    @rcomer
    Member

    No, I deliberately didn't handle color(s) in #30808

    Note the helper does not handle color because the methods already have bespoke handling for colors. E.g. stackplot maps colors to facecolor, hist with "step" type maps colors to edgecolor. What should happen if color is in **kwargs probably needs individual consideration for each method.

    I actually hadn't noticed there that the keyword for hist is the singular color.

    FWIW I think it's entirely reasonable to want to pass a single color here. For the "step" type in the given images you can already work around it by passing edgecolor='k', but you might not think of that unless you've realised that these are a bunch of unfilled polygons rather than a bunch of lines. I suspect most scientists busy plotting data do not have their head in the "what sort of artist is this" space.

    The restriction to one color per dataset goes back a long way (I reproduced with v3.0). So I guess this sort of use case just wasn't anticipated.

  7. timhoffm commented on Dec 15, 2025

    @timhoffm
    Member

    I agree that accepting a single value would be reasonable (though likely rarely as in many cases, you'll want to be able to distinguish the datasets.

    The trivial workaround for now is color=["k"] * len(data)

  8. story645 commented on Dec 15, 2025

    @story645
    Member

    No, I deliberately didn't handle color(s) in

    Sorry for not reading through before asking :/

    @gapplef it's not a bug but an artifact? I also think we should support the single color argument. Would you be interested in making a pull request to support it?

  9. rcomer commented on Dec 15, 2025

    @rcomer
    Member

    Sorry for not reading through before asking :/

    No need to apologise - I think it’s entirely reasonable and more efficient to ask someone who already has it in their head.

  10. gapplef commented on Dec 16, 2025

    @gapplef
    ContributorAuthor

    @story645 I have made a PR to support single color for multiple dataset in hist.
    I made only a minimal change, as I am not familiar with the code base.


    Also, hist supports a simple list of colors as input for multiple dataset, but plot does not support this. Is this inconsistency considered a problem?

  11. timhoffm commented on Dec 16, 2025

    @timhoffm
    Member

    Also, hist supports a simple list of colors as input for multiple dataset, but plot does not support this. Is this inconsistency considered a problem?

    No. We typically only have multiple datasets (and with that lists of colors) if there's a dependency between the data (e.g. stacked hist). We don't want to make every plotting method vectorized as that increases complexity and overhead. plot supports multiple datasets for historic reasons, but we don't go down this road further.

  12. gapplef commented on Dec 17, 2025

    @gapplef
    ContributorAuthor

    Got it, thanks.

  13. added this to the v3.11.0 milestone on Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions