@@ -113,35 +113,28 @@ class CategoryNorm(mcolors.Normalize):
113
113
"""
114
114
Preserves ordering of discrete values
115
115
"""
116
- def __init__ (self , categories ):
116
+ def __init__ (self , data ):
117
117
"""
118
118
*categories*
119
119
distinct values for mapping
120
120
121
121
Out-of-range values are mapped to np.nan
122
122
"""
123
123
124
- # facilitates cleaner DuckTyping of axis interface
124
+ self .units = StrCategoryConverter ()
125
+ self .unit_data = None
126
+ self .units .default_units (data ,
127
+ self , sort = False )
125
128
126
- class CatAxis (object ):
127
- def __init__ (self ):
128
- self .unit_data = None
129
- self .units = StrCategoryConverter ()
130
-
131
- self .axis = CatAxis ()
132
- self .axis .units .default_units (categories , self .axis ,
133
- sort = False )
134
-
135
- nvals = self .axis .unit_data .locs
136
- self .vmin = min (nvals )
137
- self .vmax = max (nvals )
129
+ self .vmin = min (self .unit_data .locs )
130
+ self .vmax = max (self .unit_data .locs )
138
131
139
132
def __call__ (self , value , clip = None ):
140
133
# gonna have to go into imshow and undo casting
141
134
value = np .asarray (value , dtype = np .int )
142
- ret = self .axis . units .convert (value , None , self . axis )
135
+ ret = self .units .convert (value , None , self )
143
136
# knock out values not in the norm
144
- mask = np .in1d (ret , self .axis . unit_data .locs ).reshape (ret .shape )
137
+ mask = np .in1d (ret , self .unit_data .locs ).reshape (ret .shape )
145
138
# normalize ret & locs
146
139
ret /= self .vmax
147
140
return np .ma .array (ret , mask = ~ mask )
@@ -162,8 +155,7 @@ def colors_from_categories(codings):
162
155
:class:`Normalize` instance
163
156
"""
164
157
if isinstance (codings , dict ):
165
- codings = codings .items ()
166
-
158
+ codings = cbook .sanitize_sequence (codings .items ())
167
159
values , colors = zip (* codings )
168
160
cmap = mcolors .ListedColormap (list (colors ))
169
161
norm = CategoryNorm (list (values ))
0 commit comments