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 aa975c2

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

File tree

Expand file treeCollapse file tree

2 files changed

+26
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-9
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
+15-4Lines changed: 15 additions & 4 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):

0 commit comments

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