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