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 63d83da

Browse filesBrowse files
committed
MNT: set the facecolor of nofill markers
Even though we are going to ignore it, set the facecolors to the user specified color and edgecolor to 'face' to maintain back-compatibility. We now warn if the user passes in an edgecolor that we ignore. closes #17849 partially reverts #17543 / d86cc2b
1 parent 1664420 commit 63d83da
Copy full SHA for 63d83da

File tree

Expand file treeCollapse file tree

2 files changed

+23
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-4
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4451,7 +4451,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44514451
s = np.ma.ravel(s)
44524452
if len(s) not in (1, x.size):
44534453
raise ValueError("s must be a scalar, or the same size as x and y")
4454-
4454+
# get the original edgecolor the user passed before we normalize
4455+
orig_edgecolor = edgecolors or kwargs.get('edgecolor', None)
44554456
c, colors, edgecolors = \
44564457
self._parse_scatter_color_args(
44574458
c, edgecolors, kwargs, x.size,
@@ -4480,6 +4481,14 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44804481
path = marker_obj.get_path().transformed(
44814482
marker_obj.get_transform())
44824483
if not marker_obj.is_filled():
4484+
if orig_edgecolor is not None:
4485+
cbook._warn_external(
4486+
f"You passed a edgecolor/edgecolors ({orig_edgecolor!r}) "
4487+
f"for an unfilled marker ({marker!r}). Matplotlib is "
4488+
"ignoring the edge color in favor of the facecolor. This "
4489+
"behavior may change in the future."
4490+
)
4491+
edgecolors = 'face'
44834492
if linewidths is None:
44844493
linewidths = rcParams['lines.linewidth']
44854494
elif np.iterable(linewidths):
@@ -4491,8 +4500,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44914500

44924501
collection = mcoll.PathCollection(
44934502
(path,), scales,
4494-
facecolors=colors if marker_obj.is_filled() else 'none',
4495-
edgecolors=edgecolors if marker_obj.is_filled() else colors,
4503+
facecolors=colors,
4504+
edgecolors=edgecolors,
44964505
linewidths=linewidths,
44974506
offsets=offsets,
44984507
transOffset=kwargs.pop('transform', self.transData),

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@ def test_scatter_unfilled(self):
18741874
coll = plt.scatter([0, 1, 2], [1, 3, 2], c=['0.1', '0.3', '0.5'],
18751875
marker=mmarkers.MarkerStyle('o', fillstyle='none'),
18761876
linewidths=[1.1, 1.2, 1.3])
1877-
assert coll.get_facecolors().shape == (0, 4) # no facecolors
1877+
assert_array_equal(coll.get_edgecolors(), coll.get_facecolors())
18781878
assert_array_equal(coll.get_edgecolors(), [[0.1, 0.1, 0.1, 1],
18791879
[0.3, 0.3, 0.3, 1],
18801880
[0.5, 0.5, 0.5, 1]])
@@ -6397,3 +6397,13 @@ def test_relative_ticklabel_sizes(size):
63976397
for name, axis in zip(['x', 'y'], [ax.xaxis, ax.yaxis]):
63986398
for tick in axis.get_major_ticks():
63996399
assert tick.label1.get_size() == axis._get_tick_label_size(name)
6400+
6401+
6402+
@pytest.mark.style('default')
6403+
def test_warn_ignored_scatter_kwargs():
6404+
with pytest.warns(UserWarning,
6405+
match=r"You passed a edgecolor/edgecolors"):
6406+
6407+
c = plt.scatter(
6408+
[0], [0], marker="+", s=500, facecolor="r", edgecolor="b"
6409+
)

0 commit comments

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