8000 Improve handling of edgecolor default, add another test. · matplotlib/matplotlib@b556789 · GitHub
[go: up one dir, main page]

Skip to content

Commit b556789

Browse files
committed
Improve handling of edgecolor default, add another test.
1 parent d852897 commit b556789

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

lib/matplotlib/collections.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -788,18 +788,17 @@ def get_edgecolor(self):
788788
else:
789789
return self._edgecolors
790790

791-
def _set_edgecolor(self, c, default=None):
791+
def _get_default_edgecolor(self):
792+
return mpl.rcParams['patch.edgecolor']
793+
794+
def _set_edgecolor(self, c):
792795
set_hatch_color = True
793796
if c is None:
794-
if default is None:
795-
if (mpl.rcParams['patch.force_edgecolor'] or
796-
not self._face_is_mapped or self._edge_default):
797-
c = mpl.rcParams['patch.edgecolor']
798-
else:
799-
c = 'none'
800-
set_hatch_color = False
797+
if (mpl.rcParams['patch.force_edgecolor'] or self._edge_default):
798+
c = self._get_default_edgecolor()
801799
else:
802-
c = default
800+
c = 'none'
801+
set_hatch_color = False
803802
if isinstance(c, str) and c == 'face':
804803
self._edgecolors = 'face'
805804
self.stale = True
@@ -809,7 +808,7 @@ def _set_edgecolor(self, c, default=None):
809808
self._hatch_color = tuple(self._edgecolors[0])
810809
self.stale = True
811810

812-
def set_edgecolor(self, c, default=None):
811+
def set_edgecolor(self, c):
813812
"""
814813
Set the edgecolor(s) of the collection.
815814
@@ -825,7 +824,7 @@ def set_edgecolor(self, c, default=None):
825824
if isinstance(c, str) and c.lower() in ("none", "face"):
826825
c = c.lower()
827826
self._original_edgecolor = c
828-
self._set_edgecolor(c, default=default)
827+
self._set_edgecolor(c)
829828

830829
def set_alpha(self, alpha):
831830
"""
@@ -1512,6 +1511,9 @@ def _add_offsets(self, segs):
15121511
segs[i] = segs[i] + offsets[io:io + 1]
15131512
return segs
15141513

1514+
def _get_default_edgecolor(self):
1515+
return mpl.rcParams['lines.color']
1516+
15151517
def set_color(self, c):
15161518
"""
15171519
Set the color(s) of the LineCollection.
@@ -1523,7 +1525,7 @@ def set_color(self, c):
15231525
sequence of rgba tuples; if it is a sequence the lines will
15241526
cycle through the sequence.
15251527
"""
1526-
self.set_edgecolor(c, default=mpl.rcParams['lines.color'])
1528+
self.set_edgecolor(c)
15271529

15281530
def get_color(self):
15291531
return self._edgecolors

lib/matplotlib/tests/test_collections.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,3 +777,18 @@ def test_color_logic(pcfunc):
777777
pc.update_scalarmappable()
778778
assert pc.get_facecolor().shape == (12, 4) # color-mapped
779779
assert pc.get_edgecolor().shape == (1, 4) # not color-mapped
780+
# Give color via tuple rather than string.
781+
pc = pcfunc(z, edgecolors=(1, 0, 0), facecolors=(0, 1, 0))
782+
assert_array_equal(pc.get_facecolor(), [[0, 1, 0, 1]])
783+
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 1]])
784+
785+
786+
def test_array_wrong_dimensions():
787+
z = np.arange(12).reshape(3, 4)
788+
pc = plt.pcolor(z)
789+
with pytest.raises(ValueError, match="^Collections can only map"):
790+
pc.set_array(z)
791+
pc.update_scalarmappable()
792+
pc = plt.pcolormesh(z)
793+
pc.set_array(z) # 2D is OK for Quadmesh
794+
pc.update_scalarmappable()

0 commit comments

Comments
 (0)
0