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