@@ -754,49 +754,70 @@ def test_legend_inverse_size_label_relationship():
754
754
@pytest .mark .style ('default' )
755
755
@pytest .mark .parametrize ('pcfunc' , [plt .pcolor , plt .pcolormesh ])
756
756
def test_color_logic (pcfunc ):
757
- rgba_none = mcolors .to_rgba_array ('none' )
758
757
z = np .arange (12 ).reshape (3 , 4 )
758
+ # Explicitly set an edgecolor.
759
759
pc = pcfunc (z , edgecolors = 'red' , facecolors = 'none' )
760
+ pc .update_scalarmappable () # This is called in draw().
761
+ # Define 2 reference "colors" here for multiple use.
760
762
face_default = mcolors .to_rgba_array (pc ._get_default_facecolor ())
761
- assert_array_equal (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
763
+ mapped = pc .get_cmap ()(pc .norm ((z .ravel ())))
764
+ # Github issue #1302:
765
+ assert mcolors .same_color (pc .get_edgecolor (), 'red' )
762
766
# Check setting attributes after initialization:
763
767
pc = pcfunc (z )
764
768
pc .set_facecolor ('none' )
765
769
pc .set_edgecolor ('red' )
766
- assert_array_equal (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
770
+ pc .update_scalarmappable ()
771
+ assert mcolors .same_color (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
767
772
pc .set_alpha (0.5 )
768
- assert_array_equal ( pc .get_edgecolor (), [[ 1 , 0 , 0 , 0.5 ]] )
769
- pc .set_edgecolor ( None ) # reset to default
773
+ pc .update_scalarmappable ( )
774
+ assert mcolors . same_color ( pc .get_edgecolor (), [[ 1 , 0 , 0 , 0.5 ]])
770
775
pc .set_alpha (None ) # restore default alpha
771
776
pc .update_scalarmappable ()
772
- assert pc .get_edgecolor ().shape == (12 , 4 ) # color-mapped
773
- pc .set_facecolor (None )
777
+ assert mcolors .same_color (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
778
+ # Reset edgecolor to default.
779
+ pc .set_edgecolor (None )
780
+ pc .update_scalarmappable ()
781
+ assert mcolors .same_color (pc .get_edgecolor (), mapped )
782
+ pc .set_facecolor (None ) # restore default for facecolor
774
783
pc .update_scalarmappable ()
775
- assert pc .get_facecolor (). shape == ( 12 , 4 ) # color- mapped
776
- assert_array_equal (pc .get_edgecolor (), rgba_none ) # default: 'none'
784
+ assert mcolors . same_color ( pc .get_facecolor (), mapped )
785
+ assert mcolors . same_color (pc .get_edgecolor (), 'none' )
777
786
# Turn off colormapping entirely:
778
787
pc .set_array (None )
779
788
pc .update_scalarmappable ()
780
- assert_array_equal (pc .get_edgecolor (), rgba_none )
781
- assert pc .get_facecolor ().shape == (1 , 4 ) # no longer color-mapped
782
- assert_array_equal (pc .get_facecolor (), face_default )
789
+ assert mcolors .same_color (pc .get_edgecolor (), 'none' )
790
+ assert mcolors .same_color (pc .get_facecolor (), face_default ) # not mapped
783
791
# Turn it back on by restoring the array (must be 1D!):
784
792
pc .set_array (z .ravel ())
785
793
pc .update_scalarmappable ()
786
- assert pc .get_facecolor (). shape == ( 12 , 4 ) # color- mapped
787
- assert_array_equal (pc .get_edgecolor (), rgba_none )
794
+ assert mcolors . same_color ( pc .get_facecolor (), mapped )
795
+ assert mcolors . same_color (pc .get_edgecolor (), 'none' )
788
796
# Give color via tuple rather than string.
789
797
pc = pcfunc (z , edgecolors = (1 , 0 , 0 ), facecolors = (0 , 1 , 0 ))
790
- assert_array_equal (pc .get_facecolor (), [[0 , 1 , 0 , 1 ]])
791
- assert_array_equal (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
792
- # Provide an RGB array.
798
+ pc .update_scalarmappable ()
799
+ assert mcolors .same_color (pc .get_facecolor (), mapped )
800
+ assert mcolors .same_color (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
801
+ # Provide an RGB array; mapping overrides it.
793
802
pc = pcfunc (z , edgecolors = (1 , 0 , 0 ), facecolors = np .ones ((12 , 3 )))
794
- assert_array_equal (pc .get_facecolor (), np .ones ((12 , 4 )))
795
- assert_array_equal (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
803
+ pc .update_scalarmappable ()
804
+ assert mcolors .same_color (pc .get_facecolor (), mapped )
805
+ assert mcolors .same_color (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
806
+ # Turn off the mapping.
807
+ pc .set_array (None )
808
+ pc .update_scalarmappable ()
809
+ assert mcolors .same_color (pc .get_facecolor (), np .ones ((12 , 3 )))
810
+ assert mcolors .same_color (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
796
811
# And an RGBA array.
797
812
pc = pcfunc (z , edgecolors = (1 , 0 , 0 ), facecolors = np .ones ((12 , 4 )))
798
- assert_array_equal (pc .get_facecolor (), np .ones ((12 , 4 )))
799
- assert_array_equal (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
813
+ pc .update_scalarmappable ()
814
+ assert mcolors .same_color (pc .get_facecolor (), mapped )
815
+ assert mcolors .same_color (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
816
+ # Turn off the mapping.
817
+ pc .set_array (None )
818
+ pc .update_scalarmappable ()
819
+ assert mcolors .same_color (pc .get_facecolor (), np .ones ((12 , 4 )))
820
+ assert mcolors .same_color (pc .get_edgecolor (), [[1 , 0 , 0 , 1 ]])
800
821
801
822
802
823
def test_LineCollection_args ():
0 commit comments