Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,15 @@ def same_color(c1, c2):
"""
Return whether the colors *c1* and *c2* are the same.
*c1*, *c2* can be single colors or lists/arrays of colors.
Parameters
----------
c1, c2 : :mpltype:`color` or list of :mpltype:`color` or RGB(A) array
Must be convertible to an (n, 4) RGBA array, where n is the same for
*c1* and *c2*.
Comment on lines +294 to +295

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).

Returns
-------
bool
"""
c1 = to_rgba_array(c1)
c2 = to_rgba_array(c2)
Expand Down
Loading