8000 Address review by @qulogic · matplotlib/matplotlib@7a26184 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a26184

Browse files
committed
Address review by @QuLogic
A test is improved, and a bug revealed by the improved test is fixed.
1 parent 8c3ab54 commit 7a26184

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/matplotlib/collections.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ def _get_default_edgecolor(self):
803803
def _set_edgecolor(self, c):
804804
set_hatch_color = True
805805
if c is None:
806-
if (mpl.rcParams['patch.force_edgecolor'] or self._edge_default):
806+
if mpl.rcParams['patch.force_edgecolor'] or self._edge_default:
807807
c = self._get_default_edgecolor()
808808
else:
809809
c = 'none'
@@ -890,7 +890,10 @@ def _set_mappable_flags(self):
890890
fc = 'array'
891891
ec = self._original_edgecolor
892892
if ec is None:
893-
ec = self._get_default_edgecolor()
893+
if mpl.rcParams['patch.force_edgecolor'] or self._edge_default:
894+
ec = self._get_default_edgecolor()
895+
else:
896+
ec = 'none'
894897
if not isinstance(ec, str):
895898
ec = 'array'
896899

@@ -947,8 +950,7 @@ def update_scalarmappable(self):
947950

948951
def get_fill(self):
949952
"""Return whether face is colored."""
950-
fill = not cbook._str_lower_equal(self._original_facecolor, "none")
951-
return fill
953+
return not cbook._str_lower_equal(self._original_facecolor, "none")
952954

953955
def update_from(self, other):
954956
"""Copy properties from other to self."""
@@ -1459,9 +1461,10 @@ def __init__(self, segments, # Can be None.
14591461
argkw = {name: val for name, val in zip(argnames, args)}
14601462
kwargs.update(argkw)
14611463
cbook.warn_deprecated(
1462-
"3.4", message="In a future release, all LineCollection "
1463-
"arguments other than the first, 'segments', will be "
1464-
"keyword-only arguments."
1464+
"3.4", message="Since %(since)s, passing LineCollection "
1465+
"arguments other than the first, 'segments', as positional "
1466+
"arguments is deprecated, and they will become keyword-only "
1467+
"arguments %(removal)s."
14651468
)
14661469
super().__init__(
14671470
zorder=zorder,

lib/matplotlib/tests/test_collections.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
1010
import matplotlib.collections as mcollections
11+
import matplotlib.colors as mcolors
1112
import matplotlib.transforms as mtransforms
1213
from matplotlib.collections import (Collection, LineCollection,
1314
EventCollection, PolyCollection)
@@ -750,10 +751,13 @@ def test_legend_inverse_size_label_relationship():
750751
assert_array_almost_equal(handle_sizes, legend_sizes, decimal=1)
751752

752753

754+
@pytest.mark.style('default')
753755
@pytest.mark.parametrize('pcfunc', [plt.pcolor, plt.pcolormesh])
754756
def test_color_logic(pcfunc):
757+
rgba_none = mcolors.to_rgba_array('none')
755758
z = np.arange(12).reshape(3, 4)
756759
pc = pcfunc(z, edgecolors='red', facecolors='none')
760+
face_default = mcolors.to_rgba_array(pc._get_default_facecolor())
757761
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 1]])
758762
# Check setting attributes after initialization:
759763
pc = pcfunc(z)
@@ -762,22 +766,25 @@ def test_color_logic(pcfunc):
762766
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 1]])
763767
pc.set_alpha(0.5)
764768
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 0.5]])
765-
pc.set_edgecolor(None)
769+
pc.set_edgecolor(None) # reset to default
770+
pc.set_alpha(None) # restore default alpha
766771
pc.update_scalarmappable()
767772
assert pc.get_edgecolor().shape == (12, 4) # color-mapped
768773
pc.set_facecolor(None)
769774
pc.update_scalarmappable()
770775
assert pc.get_facecolor().shape == (12, 4) # color-mapped
771-
assert pc.get_edgecolor().shape == (1, 4) # no longer color-mapped
776+
assert_array_equal(pc.get_edgecolor(), rgba_none) # default: 'none'
772777
# Turn off colormapping entirely:
773778
pc.set_array(None)
774779
pc.update_scalarmappable()
780+
assert_array_equal(pc.get_edgecolor(), rgba_none)
775781
assert pc.get_facecolor().shape == (1, 4) # no longer color-mapped
782+
assert_array_equal(pc.get_facecolor(), face_default)
776783
# Turn it back on by restoring the array (must be 1D!):
777784
pc.set_array(z.ravel())
778785
pc.update_scalarmappable()
779786
assert pc.get_facecolor().shape == (12, 4) # color-mapped
780-
assert pc.get_edgecolor().shape == (1, 4) # not color-mapped
787+
assert_array_equal(pc.get_edgecolor(), rgba_none)
781788
# Give color via tuple rather than string.
782789
pc = pcfunc(z, edgecolors=(1, 0, 0), facecolors=(0, 1, 0))
783790
assert_array_equal(pc.get_facecolor(), [[0, 1, 0, 1]])

0 commit comments

Comments
 (0)
0