55from numerix import absolute , arange , array , asarray , ones , divide ,\
66 transpose , log , log10 , Float , Float32 , ravel , zeros ,\
77 Int16 , Int32 , Int , Float64 , ceil , indices , \
8- shape , which , where , sqrt , asum , compress , maximum , minimum
8+ shape , which , where , sqrt , asum , compress , maximum , minimum , ma
99
1010import matplotlib .mlab
1111from artist import Artist
@@ -2034,6 +2034,10 @@ def pcolor(self, *args, **kwargs):
20342034 PCOLOR(C, **kwargs) - Use keywork args to control colormapping and
20352035 scaling; see below
20362036
2037+ X,Y and C may be masked arrays. If either C[i,j], or one
2038+ of the vertices surrounding C[i,j] (X or Y at [i,j],[i+1,j],
2039+ [i,j+1],[i=1,j+1]) is masked, nothing is plotted.
2040+
20372041 Optional keywork args are shown with their defaults below (you must
20382042 use kwargs for these):
20392043
@@ -2101,11 +2105,20 @@ def pcolor(self, *args, **kwargs):
21012105
21022106 Nx , Ny = X .shape
21032107
2108+ # convert to MA, if necessary.
2109+ C = ma .asarray (C )
2110+ X = ma .asarray (X )
2111+ Y = ma .asarray (Y )
2112+ mask = ma .getmaskarray (X )+ ma .getmaskarray (Y )
2113+ xymask = mask [0 :- 1 ,0 :- 1 ]+ mask [1 :,1 :]+ mask [0 :- 1 ,1 :]+ mask [1 :,0 :- 1 ]
2114+ # don't plot if C or any of the surrounding vertices are masked.
2115+ mask = ma .getmaskarray (C )[0 :Nx - 1 ,0 :Ny - 1 ]+ xymask
2116+
21042117 verts = [ ( (X [i ,j ], Y [i ,j ]), (X [i + 1 ,j ], Y [i + 1 ,j ]),
21052118 (X [i + 1 ,j + 1 ], Y [i + 1 ,j + 1 ]), (X [i ,j + 1 ], Y [i ,j + 1 ]))
2106- for i in range (Nx - 1 ) for j in range (Ny - 1 )]
2119+ for i in range (Nx - 1 ) for j in range (Ny - 1 ) if not mask [ i , j ] ]
21072120
2108- C = array ([C [i ,j ] for i in range (Nx - 1 ) for j in range (Ny - 1 )])
2121+ C = array ([C [i ,j ] for i in range (Nx - 1 ) for j in range (Ny - 1 ) if not mask [ i , j ] ])
21092122
21102123 if shading == 'faceted' :
21112124 edgecolors = (0 ,0 ,0 ,1 ),
@@ -2131,8 +2144,8 @@ def pcolor(self, *args, **kwargs):
21312144
21322145 self .grid (False )
21332146
2134- x = ravel ( X )
2135- y = ravel ( Y )
2147+ x = X . compressed ( )
2148+ y = X . compressed ( )
21362149 minx = amin (x )
21372150 maxx = amax (x )
21382151 miny = amin (y )
0 commit comments