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

Skip to content

Commit a257f7c

Browse files
committed
Address review by @QuLogic
A test is improved, and a bug revealed by the improved test is fixed.
1 parent 34faf5d commit a257f7c

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
@@ -802,7 +802,7 @@ def _get_default_edgecolor(self):
802802
def _set_edgecolor(self, c):
803803
set_hatch_color = True
804804
if c is None:
805-
if (mpl.rcParams['patch.force_edgecolor'] or self._edge_default):
805+
if mpl.rcParams['patch.force_edgecolor'] or self._edge_default:
806806
c = self._get_default_edgecolor()
807807
else:
808808
c = 'none'
@@ -889,7 +889,10 @@ def _set_mappable_flags(self):
889889
fc = 'array'
890890
ec = self._original_edgecolor
891891
if ec is None:
892-
ec = self._get_default_edgecolor()
892+
if mpl.rcParams['patch.force_edgecolor'] or self._edge_default:
893+
ec = self._get_default_edgecolor()
894+
else:
895+
ec = 'none'
893896
if not isinstance(ec, str):
894897
ec = 'array'
895898

@@ -946,8 +949,7 @@ def update_scalarmappable(self):
946949

947950
def get_fill(self):
948951
"""Return whether face is colored."""
949-
fill = not cbook._str_lower_equal(self._original_facecolor, "none")
950-
return fill
952+
return not cbook._str_lower_equal(self._original_facecolor, "none")
951953

952954
def update_from(self, other):
953955
"""Copy properties from other to self."""
@@ -1458,9 +1460,10 @@ def __init__(self, segments, # Can be None.
14581460
argkw = {name: val for name, val in zip(argnames, args)}
14591461
kwargs.update(argkw)
14601462
cbook.warn_deprecated(
1461-
"3.4", message="In a future release, all LineCollection "
1462-
"arguments other than the first, 'segments', will be "
1463-
"keyword-only arguments."
1463+
"3.4", message="Since %(since)s, passing LineCollection "
1464+
"arguments other than the first, 'segments', as positional "
1465+
"arguments is deprecated, and they will become keyword-only "
1466+
"arguments %(removal)s."
14641467
)
14651468
super().__init__(
14661469
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)
@@ -748,10 +749,13 @@ def test_legend_inverse_size_label_relationship():
748749
assert_array_almost_equal(handle_sizes, legend_sizes, decimal=1)
749750

750751

752+
@pytest.mark.style('default')
751753
@pytest.mark.parametrize('pcfunc', [plt.pcolor, plt.pcolormesh])
752754
def test_color_logic(pcfunc):
755+
rgba_none = mcolors.to_rgba_array('none')
753756
z = np.arange(12).reshape(3, 4)
754757
pc = pcfunc(z, edgecolors='red', facecolors='none')
758+
face_default = mcolors.to_rgba_array(pc._get_default_facecolor())
755759
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 1]])
756760
# Check setting attributes after initialization:
757761
pc = pcfunc(z)
@@ -760,22 +764,25 @@ def test_color_logic(pcfunc):
760764
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 1]])
761765
pc.set_alpha(0.5)
762766
assert_array_equal(pc.get_edgecolor(), [[1, 0, 0, 0.5]])
763-
pc.set_edgecolor(None)
767+
pc.set_edgecolor(None) # reset to default
768+
pc.set_alpha(None) # restore default alpha
764769
pc.update_scalarmappable()
765770
assert pc.get_edgecolor().shape == (12, 4) # color-mapped
766771
pc.set_facecolor(None)
767772
pc.update_scalarmappable()
768773
assert pc.get_facecolor().shape == (12, 4) # color-mapped
769-
assert pc.get_edgecolor().shape == (1, 4) # no longer color-mapped
774+
assert_array_equal(pc.get_edgecolor(), rgba_none) # default: 'none'
770775
# Turn off colormapping entirely:
771776
pc.set_array(None)
772777
pc.update_scalarmappable()
778+
assert_array_equal(pc.get_edgecolor(), rgba_none)
773779
assert pc.get_facecolor().shape == (1, 4) # no longer color-mapped
780+
assert_array_equal(pc.get_facecolor(), face_default)
774781
# Turn it back on by restoring the array (must be 1D!):
775782
pc.set_array(z.ravel())
776783
pc.update_scalarmappable()
777784
assert pc.get_facecolor().shape == (12, 4) # color-mapped
778-
assert pc.get_edgecolor().shape == (1, 4) # not color-mapped
785+
assert_array_equal(pc.get_edgecolor(), rgba_none)
779786
# Give color via tuple rather than string.
780787
pc = pcfunc(z, edgecolors=(1, 0, 0), facecolors=(0, 1, 0))
781788
assert_array_equal(pc.get_facecolor(), [[0, 1, 0, 1]])

0 commit comments

Comments
 (0)
< 2A80 /div>
0