8
8
import matplotlib as mpl
9
9
import matplotlib .pyplot as plt
10
10
import matplotlib .collections as mcollections
11
+ import matplotlib .colors as mcolors
11
12
import matplotlib .transforms as mtransforms
12
13
from matplotlib .collections import (Collection , LineCollection ,
13
14
EventCollection , PolyCollection )
@@ -750,10 +751,13 @@ def test_legend_inverse_size_label_relationship():
750
751
assert_array_almost_equal (handle_sizes , legend_sizes , decimal = 1 )
751
752
752
753
754
+ @pytest .mark .style ('default' )
753
755
@pytest .mark .parametrize ('pcfunc' , [plt .pcolor , plt .pcolormesh ])
754
756
def test_color_logic (pcfunc ):
757
+ rgba_none = mcolors .to_rgba_array ('none' )
755
758
z = np .arange (12 ).reshape (3 , 4 )
756
759
pc = pcfunc (z , edgecolors = 'red' , facecolors = 'none' )
760
+ face_default = mcolors .to_rgba_array (pc ._get_default_facecolor ())
757
761
assert_array_equal (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
758
762
# Check setting attributes after initialization:
759
763
pc = pcfunc (z )
@@ -762,22 +766,25 @@ def test_color_logic(pcfunc):
762
766
assert_array_equal (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
763
767
pc .set_alpha (0.5 )
764
768
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
766
771
pc .update_scalarmappable ()
767
772
assert pc .get_edgecolor ().shape == (12 , 4 ) # color-mapped
768
773
pc .set_facecolor (None )
769
774
pc .update_scalarmappable ()
770
775
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'
772
777
# Turn off colormapping entirely:
773
778
pc .set_array (None )
774
779
pc .update_scalarmappable ()
780
+ assert_array_equal (pc .get_edgecolor (), rgba_none )
775
781
assert pc .get_facecolor ().shape == (1 , 4 ) # no longer color-mapped
782
+ assert_array_equal (pc .get_facecolor (), face_default )
776
783
# Turn it back on by restoring the array (must be 1D!):
777
784
pc .set_array (z .ravel ())
778
785
pc .update_scalarmappable ()
779
786
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 )
781
788
# Give color via tuple rather than string.
782
789
pc = pcfunc (z , edgecolors = (1 , 0 , 0 ), facecolors = (0 , 1 , 0 ))
783
790
assert_array_equal (pc .get_facecolor (), [[0 , 1 , 0 , 1 ]])
0 commit comments