8000 MNT: Issue a warning instead of logging if RGB(A) passed to scatter(..., c) by timhoffm · Pull Request #24430 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

MNT: Issue a warning instead of logging if RGB(A) passed to scatter(..., c) #24430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4394,7 +4394,7 @@ def invalid_shape_exception(csize, xsize):
c_is_mapped = True
else: # Wrong size; it must not be intended for mapping.
if c.shape in ((3,), (4,)):
_log.warning(
_api.warn_external(
"*c* argument looks like a single numeric RGB or "
"RGBA sequence, which should be avoided as value-"
"mapping will have precedence in case its length "
Expand Down
24 changes: 14 additions & 10 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
from collections import namedtuple
import datetime
from decimal import Decimal
Expand Down Expand Up @@ -2638,15 +2639,17 @@ def get_next_color():
"conversion": "^'c' argument must be a color", # bad vals
}

if re_key is None:
assert_context = (
pytest.raises(ValueError, match=REGEXP[re_key])
if re_key is not None
else pytest.warns(match="argument looks like a single numeric RGB")
if isinstance(c_case, list) and len(c_case) == 3
else contextlib.nullcontext()
)
with assert_context:
mpl.axes.Axes._parse_scatter_color_args(
c=c_case, edgecolors="black", kwargs={}, xsize=xsize,
get_next_color_func=get_next_color)
else:
with pytest.raises(ValueError, match=REGEXP[re_key]):
mpl.axes.Axes._parse_scatter_color_args(
c=c_case, edgecolors="black", kwargs={}, xsize=xsize,
get_next_color_func=get_next_color)

@mpl.style.context('default')
@check_figures_equal(extensions=["png"])
Expand Down Expand Up @@ -6803,9 +6806,9 @@ def test_color_length_mismatch():
fig, ax = plt.subplots()
with pytest.raises(ValueError):
ax.scatter(x, y, c=colors)
c_rgb = (0.5, 0.5, 0.5)
ax.scatter(x, y, c=c_rgb)
ax.scatter(x, y, c=[c_rgb] * N)
with pytest.warns(match="argument looks like a single numeric RGB"):
ax.scatter(x, y, c=(0.5, 0.5, 0.5))
ax.scatter(x, y, c=[(0.5, 0.5, 0.5)] * N)


def test_eventplot_legend():
Expand Down Expand Up @@ -7688,7 +7691,8 @@ def test_2dcolor_plot(fig_test, fig_ref):
# plot with 1D-color:
axs = fig_test.subplots(5)
axs[0].plot([1, 2], [1, 2], c=color.reshape(-1))
axs[1].scatter([1, 2], [1, 2], c=color.reshape(-1))
with pytest.warns(match="argument looks like a single numeric RGB"):
axs[1].scatter([1, 2], [1, 2], c=color.reshape(-1))
axs[2].step([1, 2], [1, 2], c=color.reshape(-1))
axs[3].hist(np.arange(10), color=color.reshape(-1))
axs[4].bar(np.arange(10), np.arange(10), color=color.reshape(-1))
Expand Down
0