Skip to content

DOC: clarify valid inputs and return type of same_color#31904

Draft
rcomer wants to merge 1 commit into
matplotlib:mainfrom
rcomer:doc-same_color
Draft

DOC: clarify valid inputs and return type of same_color#31904
rcomer wants to merge 1 commit into
matplotlib:mainfrom
rcomer:doc-same_color

Conversation

@rcomer

@rcomer rcomer commented Jun 15, 2026

Copy link
Copy Markdown
Member

PR summary

I passed an (n, m, 3) RGB array and a single color string, hoping to get an (n, m) boolean array back. same_color doesn't do that.

I copied the input type specification from the to_rbga_array docstring.

AI Disclosure

I asked CoPilot to check the docstring against Numpydoc style. It modified the whitespace and added the "Returns" section.

PR checklist

@rcomer rcomer added the Documentation: API files in lib/ and doc/api label Jun 15, 2026
@rcomer

rcomer commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

Renders like this.

@story645

Copy link
Copy Markdown
Member

passed an (n, m, 3) RGB array and a single color string

I think it'd be cool if that worked.

Comment thread lib/matplotlib/colors.py
Comment on lines +294 to +295
Must be convertible to an (n, 4) RGBA array, where n is the same for
*c1* and *c2*.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the mention of (n, 4) here confuses the point I think you're trying to make w/ this PR that c1 and c2 must have the same number of colors.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I was also trying to say something about the acceptable shape of an array. It can be 1D if an array of strings or 2D if it's RGB(A), but not sure the best way to say that concisely and make it obvious that the second dim is channels. 🫤

@story645 story645 Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm confused b/c this works so I'm not sure what needs to be said about shape/channels:

In [13]: mcolors.same_color([(0,0,.2), (0,0, .2, .1), "green", '#0f0f0f80', ('green', .2)], ["green" for _ in range(5)])
Out[13]: np.False_

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The docstring states that you can pass an array. So I passed a (n, m, 3) shaped RGB array. It errored in to_rgba_array. Passing a (n, 3) shaped RGB array does work though.

@story645 story645 Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think separating concerns might be clearer here? something like:

*c1* and *c2* must be of the same length. RGB(A) arrays must be of shape (ncolors, 3) or (ncolors, 4).

@rcomer rcomer marked this pull request as draft June 15, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants