Skip to content

Commit 88cd5fd

Browse files
committed
Fix scatter edgecolor for unfilled points
For unfilled markers, the edgecolor -- if specified -- has precedence over the facecolor. closes has2k1/plotnine#100
1 parent 49d5ced commit 88cd5fd

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

doc/api/api_changes/2017-12-14-HK.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Scatter plot unfilled marker edgecolor
2+
--------------------------------------
3+
4+
For :meth:`~matplotlib.axes.Axes.scatter`, when both the `facecolor`
5+
and `edgecolor` are specified for unfilled marker types, the `edgecolor`
6+
is used. Previously, the points took on the `facecolor`.

lib/matplotlib/axes/_axes.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3873,8 +3873,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
38733873
If it is 'none', the patch boundary will not
38743874
be drawn.
38753875
3876-
For non-filled markers, the `edgecolors` kwarg
3877-
is ignored and forced to 'face' internally.
3876+
For non-filled markers , the `edgecolors` kwarg (if it is not
3877+
None, 'face' or 'none') dictates the color of the marker.
38783878
38793879
Returns
38803880
-------
@@ -4024,7 +4024,8 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
40244024
path = marker_obj.get_path().transformed(
40254025
marker_obj.get_transform())
40264026
if not marker_obj.is_filled():
4027-
edgecolors = 'face'
4027+
if edgecolors is None:
4028+
edgecolors = 'face'
40284029
linewidths = rcParams['lines.linewidth']
40294030

40304031
offsets = np.column_stack([x, y])

lib/matplotlib/tests/test_axes.py

+15
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,21 @@ def test_scatter_color():
17331733
plt.scatter([1, 2, 3], [1, 2, 3], color=[1, 2, 3])
17341734

17351735

1736+
@pytest.mark.parametrize(('facecolor', 'edgecolor', 'expected_color'), [
1737+
('red', 'cyan', 'cyan'),
1738+
(None, 'cyan', 'cyan'),
1739+
('red', None, 'red')
1740+
])
1741+
def test_scatter_edgecolor(facecolor, edgecolor, expected_color):
1742+
fig, ax = plt.subplots()
1743+
artist = ax.scatter(x=[1, 2, 3], y=[1, 2, 3], s=550,
1744+
linewidth=5, marker='2',
1745+
facecolor=facecolor,
1746+
edgecolor=edgecolor)
1747+
result_color = artist.get_edgecolor()[0]
1748+
assert mcolors.to_hex(result_color) == mcolors.to_hex(expected_color)
1749+
1750+
17361751
def test_as_mpl_axes_api():
17371752
# tests the _as_mpl_axes api
17381753
from matplotlib.projections.polar import PolarAxes

0 commit comments

Comments
 (0)