FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

In scatter, fix single rgb edgecolors handling by efiring · Pull Request #19539 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 5 additions & 0 deletions lib/matplotlib/axes/_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
x, y, s, c, colors, edgecolors, linewidths = \
cbook._combine_masks(
x, y, s, c, colors, edgecolors, linewidths)
# Unmask edgecolors if it was actually a single RGB or RGBA.
if (x.size in (3, 4)

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Do we need a similar block for colors as well?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I believe that is already an (N,4) array out of _parse_scatter_color_args and should have broadcast correctly with the masks.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, because the case that was problematic for colors was the case where edgecolors was being
set from colors, above all this. So handling edgecolors here takes care of it.

and np.ma.is_masked(edgecolors)
and not np.ma.is_masked(orig_edgecolor)):
edgecolors = edgecolors.data

scales = s # Renamed for readability below.

Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,15 @@ def test_scatter_size_arg_size(self):
with pytest.raises(ValueError, match='float array-like'):
plt.scatter(x, x, 'foo')

def test_scatter_edgecolor_RGB(self):
# Github issue 19066
coll = plt.scatter([1, 2, 3], [1, np.nan, np.nan],
edgecolor=(1, 0, 0))
assert mcolors.same_color(coll.get_edgecolor(), (1, 0, 0))
coll = plt.scatter([1, 2, 3, 4], [1, np.nan, np.nan, 1],
edgecolor=(1, 0, 0, 1))
assert mcolors.same_color(coll.get_edgecolor(), (1, 0, 0, 1))

@check_figures_equal(extensions=["png"])
def test_scatter_invalid_color(self, fig_test, fig_ref):
ax = fig_test.subplots()
Expand Down

Back | FazBrowse Home | New Git URL