@@ -171,7 +171,7 @@ def __init__(self,
171
171
# Flags: do colors come from mapping an array?
172
172
self ._face_is_mapped = True
173
173
self ._edge_is_mapped = False
174
-
174
+ self . _mapped_colors = None # Calculated in update_scalarmappable
175
175
self ._hatch_color = mcolors .to_rgba (mpl .rcParams ['hatch.color' ])
176
176
self .set_facecolor (facecolors )
177
177
self .set_edgecolor (edgecolors )
@@ -853,57 +853,74 @@ def get_linestyle(self):
853
853
return self ._linestyles
854
854
855
855
def _set_mappable_flags (self ):
856
+ edge0 = self ._edge_is_mapped
857
+ face0 = self ._face_is_mapped
856
858
if self ._A is None :
857
859
self ._edge_is_mapped = False
858
860
self ._face_is_mapped = False
859
- return False # Nothing to map
860
-
861
- # Typical mapping: centers, not edges.
862
- self ._face_is_mapped = True
863
- self ._edge_is_mapped = False
864
-
865
- # Make the colors None or a string. (If None, it is a default.)
866
- fc = self ._original_facecolor
867
- if not (fc is None or isinstance (fc , str )):
868
- fc = 'array'
869
- ec = self ._original_edgecolor
870
- if not (ec is None or isinstance (ec , str )):
871
- ec = 'array'
861
+ # return False # Nothing to map
862
+ else :
863
+ # Typical mapping: centers, not edges.
864
+ self ._face_is_mapped = True
865
+ self ._edge_is_mapped = False
872
866
873
- # Handle special cases.
874
- if fc == 'none' :
875
- self ._face_is_mapped = False
876
- if ec in ('face' , 'none' , None ):
877
- self ._edge_is_mapped = True
878
- if ec == 'face' :
879
- self ._edge_is_mapped = self ._face_is_mapped
880
- return self ._face_is_mapped or self ._edge_is_mapped
867
+ # Make the colors None or a string. (If None, it is a default.)
868
+ fc = self ._original_facecolor
869
+ if not (fc is None or isinstance (fc , str )):
870
+ fc = 'array'
871
+ ec = self ._original_edgecolor
872
+ if not (ec is None or isinstance (ec , str )):
873
+ ec = 'array'
874
+
875
+ # Handle special cases.
876
+ if fc == 'none' :
877
+ self ._face_is_mapped = False
878
+ if ec in ('face' , 'none' , None ):
879
+ self ._edge_is_mapped = True
880
+ if ec == 'face' :
881
+ self ._edge_is_mapped = self ._face_is_mapped
882
+
883
+ mapped = self ._face_is_mapped or self ._edge_is_mapped
884
+ changed = (self ._edge_is_mapped != edge0
885
+ or self ._face_is_mapped != face0 )
886
+ return mapped or changed
881
887
882
888
def update_scalarmappable (self ):
883
- """Update colors from the scalar mappable array, if any."""
889
+ """
890
+ Update colors from the scalar mappable array, if any.
891
+
892
+ Assign colors to edges and faces based on the array and/or
893
+ colors that were directly set, as appropriate.
894
+ """
884
895
if not self ._set_mappable_flags ():
885
896
return
886
- # QuadMesh can map 2d arrays (but pcolormesh supplies 1d array)
887
- if self ._A .ndim > 1 and not isinstance (self , QuadMesh ):
888
- raise ValueError ('Collections can only map rank 1 arrays' )
889
- if not self ._check_update ("array" ):
890
- return
891
- if np .iterable (self ._alpha ):
892
- if self ._alpha .size != self ._A .size :
893
- raise ValueError (f'Data array shape, { self ._A .shape } '
894
- 'is incompatible with alpha array shape, '
895
- f'{ self ._alpha .shape } . '
896
- 'This can occur with the deprecated '
897
- 'behavior of the "flat" shading option, '
898
- 'in which a row and/or column of the data '
899
- 'array is dropped.' )
900
- # pcolormesh, scatter, maybe others flatten their _A
901
- self ._alpha = self ._alpha .reshape (self ._A .shape )
897
+ # Allow possibility to call 'self.set_array(None)'.
898
+ if self ._check_update ("array" ) and self ._A is not None :
899
+ # QuadMesh can map 2d arrays (but pcolormesh supplies 1d array)
900
+ if self ._A .ndim > 1 and not isinstance (self , QuadMesh ):
901
+ raise ValueError ('Collections can only map rank 1 arrays' )
902
+ if np .iterable (self ._alpha ):
903
+ if self ._alpha .size != self ._A .size :
904
+ raise ValueError (
905
+ f'Data array shape, { self ._A .shape } '
906
+ 'is incompatible with alpha array shape, '
907
+ f'{ self ._alpha .shape } . '
908
+ 'This can occur with the deprecated '
909
+ 'behavior of the "flat" shading option, '
910
+ 'in which a row and/or column of the data '
911
+ 'array is dropped.' )
912
+ # pcolormesh, scatter, maybe others flatten their _A
913
+ self ._alpha = self ._alpha .reshape (self ._A .shape )
914
+ self ._mapped_colors = self .to_rgba (self ._A , self ._alpha )
902
915
903
916
if self ._face_is_mapped :
904
- self ._facecolors = self .to_rgba (self ._A , self ._alpha )
917
+ self ._facecolors = self ._mapped_colors
918
+ else :
919
+ self ._set_facecolor (self ._original_facecolor )
905
920
if self ._edge_is_mapped :
906
- self ._edgecolors = self .to_rgba (self ._A , self ._alpha )
921
+ self ._edgecolors = self ._mapped_colors
922
+ else :
923
+ self ._set_edgecolor (self ._original_edgecolor )
907
924
self .stale = True
908
925
909
926
@cbook .deprecated ("3.4" )
@@ -1881,7 +1898,6 @@ def __init__(self, triangulation, **kwargs):
1881
1898
super ().__init__ (** kwargs )
1882
1899
self ._triangulation = triangulation
1883
1900
self ._shading = 'gouraud'
1884
- self ._face_is_mapped = True
1885
1901
1886
1902
self ._bbox = transforms .Bbox .unit ()
1887
1903
0 commit comments