@@ -754,49 +754,70 @@ def test_legend_inverse_size_label_relationship():
754754@pytest .mark .style ('default' )
755755@pytest .mark .parametrize ('pcfunc' , [plt .pcolor , plt .pcolormesh ])
756756def test_color_logic (pcfunc ):
757- rgba_none = mcolors .to_rgba_array ('none' )
758757 z = np .arange (12 ).reshape (3 , 4 )
758+ # Explicitly set an edgecolor.
759759 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.
760762 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' )
762766 # Check setting attributes after initialization:
763767 pc = pcfunc (z )
764768 pc .set_facecolor ('none' )
765769 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 ]])
767772 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 ]])
770775 pc .set_alpha (None ) # restore default alpha
771776 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
774783 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' )
777786 # Turn off colormapping entirely:
778787 pc .set_array (None )
779788 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
783791 # Turn it back on by restoring the array (must be 1D!):
784792 pc .set_array (z .ravel ())
785793 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' )
788796 # Give color via tuple rather than string.
789797 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.
793802 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 ]])
796811 # And an RGBA array.
797812 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 ]])
800821
801822
802823def test_LineCollection_args ():
0 commit comments