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 d6f7ccc

Browse filesBrowse files
committed
make Axes._parse_scatter_color_args static
1 parent ac0525e commit d6f7ccc
Copy full SHA for d6f7ccc

File tree

Expand file treeCollapse file tree

2 files changed

+37
-18
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-18
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4013,7 +4013,9 @@ def dopatch(xs, ys, **kwargs):
40134013
return dict(whiskers=whiskers, caps=caps, boxes=boxes,
40144014
medians=medians, fliers=fliers, means=means)
40154015

4016-
def _parse_scatter_color_args(self, c, edgecolors, kwargs, xshape, yshape):
4016+
@staticmethod
4017+
def _parse_scatter_color_args(c, edgecolors, kwargs, xshape, yshape,
4018+
get_next_color_func):
40174019
"""
40184020
Helper function to process color related arguments of `.Axes.scatter`.
40194021
@@ -4023,7 +4025,7 @@ def _parse_scatter_color_args(self, c, edgecolors, kwargs, xshape, yshape):
40234025
- kwargs['facecolors']
40244026
- kwargs['facecolor']
40254027
- kwargs['color'] (==kwcolor)
4026-
- 'b' if in classic mode else next color from color cycle
4028+
- 'b' if in classic mode else the result of ``get_next_color_func()``
40274029
40284030
Argument precedence for edgecolors:
40294031
@@ -4044,6 +4046,9 @@ def _parse_scatter_color_args(self, c, edgecolors, kwargs, xshape, yshape):
40444046
Note: The dict is modified by this function.
40454047
xshape, yshape : tuple of int
40464048
The shape of the x and y arrays passed to `.Axes.scatter`.
4049+
get_next_color_func : callable
4050+
A callable that returns a color. This color is used as facecolor
4051+
if no other color is provided.
40474052
40484053
Returns
40494054
-------
@@ -4090,7 +4095,7 @@ def _parse_scatter_color_args(self, c, edgecolors, kwargs, xshape, yshape):
40904095
if c is None:
40914096
c = (facecolors if facecolors is not None
40924097
else "b" if rcParams['_internal.classic_mode']
4093-
else self._get_patches_for_fill.get_next_color())
4098+
else get_next_color_func())
40944099

40954100
# After this block, c_array will be None unless
40964101
# c is an array for mapping. The potential ambiguity
@@ -4289,8 +4294,9 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
42894294
s = np.ma.ravel(s) # This doesn't have to match x, y in size.
42904295

42914296
c, colors, edgecolors = \
4292-
self._parse_scatter_color_args(c, edgecolors, kwargs,
4293-
xshape, yshape)
4297+
self._parse_scatter_color_args(
4298+
c, edgecolors, kwargs, xshape, yshape,
4299+
get_next_color_func=self._get_patches_for_fill.get_next_color)
42944300

42954301
# `delete_masked_points` only modifies arguments of the same length as
42964302
# `x`.

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+26-13Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,19 +1793,30 @@ def test_scatter_color(self):
17931793

17941794
@pytest.mark.parametrize('c_case, re_key', params_test_scatter_c)
17951795
def test_scatter_c(self, c_case, re_key):
1796+
def get_next_color():
1797+
return 'blue' # currently unused
1798+
1799+
from matplotlib.axes import Axes
1800+
1801+
xshape = yshape = (4,)
1802+
17961803
# Additional checking of *c* (introduced in #11383).
17971804
REGEXP = {
17981805
"shape": "^'c' argument has [0-9]+ elements", # shape mismatch
17991806
"conversion": "^'c' argument must be a mpl color", # bad vals
18001807
}
1801-
x = y = [0, 1, 2, 3]
1802-
fig, ax = plt.subplots()
18031808

18041809
if re_key is None:
1805-
ax.scatter(x, y, c=c_case, edgecolors="black")
1810+
Axes._parse_scatter_color_args(
1811+
c=c_case, edgecolors="black", kwargs={},
1812+
xshape=xshape, yshape=yshape,
1813+
get_next_color_func=get_next_color)
18061814
else:
18071815
with pytest.raises(ValueError, match=REGEXP[re_key]):
1808-
ax.scatter(x, y, c=c_case, edgecolors="black")
1816+
Axes._parse_scatter_color_args(
1817+
c=c_case, edgecolors="black", kwargs={},
1818+
xshape=xshape, yshape=yshape,
1819+
get_next_color_func=get_next_color)
18091820

18101821

18111822
def _params(c=None, xshape=(2,), yshape=(2,), **kwargs):
@@ -1829,11 +1840,12 @@ def _params(c=None, xshape=(2,), yshape=(2,), **kwargs):
18291840
_result(c=['b', 'g'], colors=np.array([[0, 0, 1, 1], [0, .5, 0, 1]]))),
18301841
])
18311842
def test_parse_scatter_color_args(params, expected_result):
1843+
def get_next_color():
1844+
return 'blue' # currently unused
1845+
18321846
from matplotlib.axes import Axes
1833-
dummyself = 'UNUSED' # self is only used in one case, which we do not
1834-
# test. Therefore we can get away without costly
1835-
# creating an Axes instance.
1836-
c, colors, _edgecolors = Axes._parse_scatter_color_args(dummyself, *params)
1847+
c, colors, _edgecolors = Axes._parse_scatter_color_args(
1848+
*params, get_next_color_func=get_next_color)
18371849
assert c == expected_result.c
18381850
assert_allclose(colors, expected_result.colors)
18391851

@@ -1855,15 +1867,16 @@ def test_parse_scatter_color_args(params, expected_result):
18551867
(dict(color='r', edgecolor='g'), 'g'),
18561868
])
18571869
def test_parse_scatter_color_args_edgecolors(kwargs, expected_edgecolors):
1870+
def get_next_color():
1871+
return 'blue' # currently unused
1872+
18581873
from matplotlib.axes import Axes
1859-
dummyself = 'UNUSED' # self is only used in one case, which we do not
1860-
# test. Therefore we can get away without costly
1861-
# creating an Axes instance.
18621874
c = kwargs.pop('c', None)
18631875
edgecolors = kwargs.pop('edgecolors', None)
18641876
_, _, result_edgecolors = \
1865-
Axes._parse_scatter_color_args(dummyself, c, edgecolors, kwargs,
1866-
xshape=(2,), yshape=(2,))
1877+
Axes._parse_scatter_color_args(c, edgecolors, kwargs,
1878+
xshape=(2,), yshape=(2,),
1879+
get_next_color_func=get_next_color)
18671880
assert result_edgecolors == expected_edgecolors
18681881

18691882

0 commit comments

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