Skip to content

Fix linewidths and colors for scatter() with unfilled markers #17543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4393,8 +4393,9 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
- 'none': No patch boundary will be drawn.
- A color or sequence of colors.

For non-filled markers, the *edgecolors* kwarg is ignored and
forced to 'face' internally.
For non-filled markers, *edgecolors* is ignored. Instead, the color
is determined like with 'face', i.e. from *c*, *colors*, or
*facecolors*.

plotnonfinite : bool, default: False
Set to plot points with nonfinite *c*, in conjunction with
Expand Down Expand Up @@ -4476,7 +4477,6 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
path = marker_obj.get_path().transformed(
marker_obj.get_transform())
if not marker_obj.is_filled():
edgecolors = 'face'
if linewidths is None:
linewidths = rcParams['lines.linewidth']
elif np.iterable(linewidths):
Expand All @@ -4488,8 +4488,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,

collection = mcoll.PathCollection(
(path,), scales,
facecolors=colors,
edgecolors=edgecolors,
facecolors=colors if marker_obj.is_filled() else 'none',
edgecolors=edgecolors if marker_obj.is_filled() else colors,
linewidths=linewidths,
offsets=offsets,
transOffset=kwargs.pop('transform', self.transData),
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ def _recache(self):
self._snap_threshold = None
self._joinstyle = 'round'
self._capstyle = 'butt'
self._filled = True
# Initial guess: Assume the marker is filled unless the fillstyle is
# set to 'none'. The marker function will override this for unfilled
# markers.
self._filled = self._fillstyle != 'none'
self._marker_function()

def __bool__(self):
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,16 @@ def test_scatter_color(self):
with pytest.raises(ValueError):
plt.scatter([1, 2, 3], [1, 2, 3], color=[1, 2, 3])

def test_scatter_unfilled(self):
coll = plt.scatter([0, 1, 2], [1, 3, 2], c=['0.1', '0.3', '0.5'],
marker=mmarkers.MarkerStyle('o', fillstyle='none'),
linewidths=[1.1, 1.2, 1.3])
assert coll.get_facecolors().shape == (0, 4) # no facecolors
assert_array_equal(coll.get_edgecolors(), [[0.1, 0.1, 0.1, 1],
[0.3, 0.3, 0.3, 1],
[0.5, 0.5, 0.5, 1]])
assert_array_equal(coll.get_linewidths(), [1.1, 1.2, 1.3])

def test_scatter_size_arg_size(self):
x = np.arange(4)
with pytest.raises(ValueError):
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/tests/test_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import pytest


def test_marker_fillstyle():
marker_style = markers.MarkerStyle(marker='o', fillstyle='none')
assert marker_style.get_fillstyle() == 'none'
assert not marker_style.is_filled()


def test_markers_valid():
marker_style = markers.MarkerStyle()
mrk_array = np.array([[-0.5, 0],
Expand Down