🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@gapplef
Copy link
Contributor

@gapplef gapplef commented Dec 16, 2025

PR summary

Close #30857 with minimal change

if mcolors.is_color_like(color):
    color = [color]*nx

If a single valid color is provided, duplicate it to match the size of the dataset.

PR checklist

@timhoffm
Copy link
Member

The code itself is fine. Please update the docstring and ad a release note. See https://matplotlib.org/devdocs/devel/api_changes.html#announce-new-and-deprecated-api.

@gapplef
Copy link
Contributor Author

gapplef commented Dec 17, 2025

Done. @timhoffm

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forgot to mention: Could you please also add a test?

@gapplef
Copy link
Contributor Author

gapplef commented Dec 18, 2025

I have add a new test for hist and update the what's news.

# Test a single color for multiple datasets
# https://github.com/matplotlib/matplotlib/issues/30857
data = [[0, 1, 2], [3, 4, 5]]
plt.hist(data, color='k')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only tests that the call does not blow up. It does not verify whether the right thing happens. Please refine:

Suggested change
plt.hist(data, color='k')
_, _, bar_containers = plt.hist(data, color='k')
for p in bar_containers[0].patches:
assert mcolor.same_color(p.get_facecolor(), 'k')
for p in bar_containers[1].patches:
assert mcolor.same_color(p.get_facecolor(), 'k')

Comment on lines +2584 to +2585
# Test a single color for multiple datasets
# https://github.com/matplotlib/matplotlib/issues/30857
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Test a single color for multiple datasets
# https://github.com/matplotlib/matplotlib/issues/30857

The content of the first line is already expressed through the function name.
We typically do not reference github issues. For future readers, it does not matter whether the test was added as part of the original implementation or through a later issue. If somebody really want to know this they can reconstruct the PR from the commit and the issue from the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants