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

Skip to content

Commit 2bad893

Browse files
committed
Fix linewidths and colors for scatter() with unfilled markers
- Previously, linewidths for unfilled markers were hard-coded to use rcParams['lines.linewidth'], the keyword argument linewidths was ignored. - Previously, markers with fillstyle='none' still were drawn with a facecolor.
1 parent bdde835 commit 2bad893

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,15 +4492,15 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44924492
path = marker_obj.get_path().transformed(
44934493
marker_obj.get_transform())
44944494
if not marker_obj.is_filled():
4495-
edgecolors = 'face'
4496-
linewidths = rcParams['lines.linewidth']
4495+
if linewidths is None:
4496+
linewidths = rcParams['lines.linewidth']
44974497

44984498
offsets = np.ma.column_stack([x, y])
44994499

45004500
collection = mcoll.PathCollection(
45014501
(path,), scales,
4502-
facecolors=colors,
4503-
edgecolors=edgecolors,
4502+
facecolors=colors if marker_obj.is_filled() else 'none',
4503+
edgecolors=edgecolors if marker_obj.is_filled() else colors,
45044504
linewidths=linewidths,
45054505
offsets=offsets,
45064506
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)