Skip to content

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

Merged
story645 merged 1 commit into
matplotlib:mainfrom
rcomer:doc-same_color
Jun 16, 2026
Merged

DOC: clarify valid inputs and return type of same_color#31904
story645 merged 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 Outdated
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
@github-actions github-actions Bot removed the Documentation: API files in lib/ and doc/api label Jun 16, 2026
@rcomer

rcomer commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

Now renders like this

@rcomer
rcomer marked this pull request as ready for review June 16, 2026 14:39
@story645 story645 added this to the v3.11.1 milestone Jun 16, 2026
@story645 story645 added the Documentation: API files in lib/ and doc/api label Jun 16, 2026
@story645
story645 merged commit ca8df27 into matplotlib:main Jun 16, 2026
44 of 46 checks passed
@rcomer
rcomer deleted the doc-same_color branch June 16, 2026 16:57
@rcomer

rcomer commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

Thanks @story645!

story645 pushed a commit that referenced this pull request Jun 16, 2026
…e_color` (#31911)

Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
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