5
5
from numerix import absolute , arange , array , asarray , ones , divide ,\
6
6
transpose , log , log10 , Float , Float32 , ravel , zeros ,\
7
7
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
9
9
10
10
import matplotlib .mlab
11
11
from artist import Artist
@@ -2034,6 +2034,10 @@ def pcolor(self, *args, **kwargs):
2034
2034
PCOLOR(C, **kwargs) - Use keywork args to control colormapping and
2035
2035
scaling; see below
2036
2036
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
+
2037
2041
Optional keywork args are shown with their defaults below (you must
2038
2042
use kwargs for these):
2039
2043
@@ -2101,11 +2105,20 @@ def pcolor(self, *args, **kwargs):
2101
2105
2102
2106
Nx , Ny = X .shape
2103
2107
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
+
2104
2117
verts = [ ( (X [i ,j ], Y [i ,j ]), (X [i + 1 ,j ], Y [i + 1 ,j ]),
2105
2118
(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 ] ]
2107
2120
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 ] ])
2109
2122
2110
2123
if shading == 'faceted' :
2111
2124
edgecolors = (0 ,0 ,0 ,1 ),
@@ -2131,8 +2144,8 @@ def pcolor(self, *args, **kwargs):
2131
2144
2132
2145
self .grid (False )
2133
2146
2134
- x = ravel ( X )
2135
- y = ravel ( Y )
2147
+ x = X . compressed ( )
2148
+ y = X . compressed ( )
2136
2149
minx = amin (x )
2137
2150
maxx = amax (x )
2138
2151
miny = amin (y )
0 commit comments