Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 500967b

Browse filesBrowse files
authored
Merge pull request #24430 from timhoffm/scatter-warn
MNT: Issue a warning instead of logging if RGB(A) passed to scatter(..., c)
2 parents 37c4e9d + 2058467 commit 500967b
Copy full SHA for 500967b

File tree

Expand file treeCollapse file tree

2 files changed

+15
-11
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-11
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4394,7 +4394,7 @@ def invalid_shape_exception(csize, xsize):
43944394
c_is_mapped = True
43954395
else: # Wrong size; it must not be intended for mapping.
43964396
if c.shape in ((3,), (4,)):
4397-
_log.warning(
4397+
_api.warn_external(
43984398
"*c* argument looks like a single numeric RGB or "
43994399
"RGBA sequence, which should be avoided as value-"
44004400
"mapping will have precedence in case its length "

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+14-10Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
from collections import namedtuple
23
import datetime
34
from decimal import Decimal
@@ -2638,15 +2639,17 @@ def get_next_color():
26382639
"conversion": "^'c' argument must be a color", # bad vals
26392640
}
26402641

2641-
if re_key is None:
2642+
assert_context = (
2643+
pytest.raises(ValueError, match=REGEXP[re_key])
2644+
if re_key is not None
2645+
else pytest.warns(match="argument looks like a single numeric RGB")
2646+
if isinstance(c_case, list) and len(c_case) == 3
2647+
else contextlib.nullcontext()
2648+
)
2649+
with assert_context:
26422650
mpl.axes.Axes._parse_scatter_color_args(
26432651
c=c_case, edgecolors="black", kwargs={}, xsize=xsize,
26442652
get_next_color_func=get_next_color)
2645-
else:
2646-
with pytest.raises(ValueError, match=REGEXP[re_key]):
2647-
mpl.axes.Axes._parse_scatter_color_args(
2648-
c=c_case, edgecolors="black", kwargs={}, xsize=xsize,
2649-
get_next_color_func=get_next_color)
26502653

26512654
@mpl.style.context('default')
26522655
@check_figures_equal(extensions=["png"])
@@ -6803,9 +6806,9 @@ def test_color_length_mismatch():
68036806
fig, ax = plt.subplots()
68046807
with pytest.raises(ValueError):
68056808
ax.scatter(x, y, c=colors)
6806-
c_rgb = (0.5, 0.5, 0.5)
6807-
ax.scatter(x, y, c=c_rgb)
6808-
ax.scatter(x, y, c=[c_rgb] * N)
6809+
with pytest.warns(match="argument looks like a single numeric RGB"):
6810+
ax.scatter(x, y, c=(0.5, 0.5, 0.5))
6811+
ax.scatter(x, y, c=[(0.5, 0.5, 0.5)] * N)
68096812

68106813

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.