Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5c6e4a

Browse files
committed
Fix colors for scatter() with unfilled markers
Previously, markers with fillstyle='none' still were drawn with a facecolor.
1 parent c283e70 commit f5c6e4a

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4480,7 +4480,6 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44804480
path = marker_obj.get_path().transformed(
44814481
marker_obj.get_transform())
44824482
if not marker_obj.is_filled():
4483-
edgecolors = 'face'
44844483
if linewidths is None:
44854484
linewidths = rcParams['lines.linewidth']
44864485
elif np.iterable(linewidths):
@@ -4492,8 +4491,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44924491

44934492
collection = mcoll.PathCollection(
44944493
(path,), scales,
4495-
facecolors=colors,
4496-
edgecolors=edgecolors,
4494+
facecolors=colors if marker_obj.is_filled() else 'none',
4495+
edgecolors=edgecolors if marker_obj.is_filled() else colors,
44974496
linewidths=linewidths,
44984497
offsets=offsets,
44994498
transOffset=kwargs.pop('transform', self.transData),

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,16 @@ def test_scatter_color(self):
18371837
with pytest.raises(ValueError):
18381838
plt.scatter([1, 2, 3], [1, 2, 3], color=[1, 2, 3])
18391839

1840+
def test_scatter_unfilled(self):
1841+
coll = plt.scatter([0, 1, 2], [1, 3, 2], c=['0.1', '0.3', '0.5'],
1842+
marker=mmarkers.MarkerStyle('o', fillstyle='none'),
1843+
linewidths=[1.1, 1.2, 1.3])
1844+
assert coll.get_facecolors().shape == (0, 4) # no facecolors
1845+
assert_array_equal(coll.get_edgecolors(), [[0.1, 0.1, 0.1, 1],
1846+
[0.3, 0.3, 0.3, 1],
1847+
[0.5, 0.5, 0.5, 1]])
1848+
assert_array_equal(coll.get_linewidths(), [1.1, 1.2, 1.3])
1849+
18401850
def test_scatter_size_arg_size(self):
18411851
x = np.arange(4)
18421852
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)