20
20
NP_NEW = (LooseVersion (np .version .version ) >= LooseVersion ('1.7' ))
21
21
22
22
23
- def to_str_array (data , maxlen = 100 ):
23
+ def to_array (data , maxlen = 100 ):
24
24
if NP_NEW :
25
- return np .array (data , dtype = np .unicode )
25
+ return np .array (data )
26
+ # dtype=np.unicode)
26
27
if cbook .is_scalar_or_string (data ):
27
28
data = [data ]
28
29
try :
@@ -38,12 +39,11 @@ class StrCategoryConverter(munits.ConversionInterface):
38
39
39
40
Conversion typically happens in the following order:
40
41
1. default_units:
41
- creates unit_data category-integer mapping and binds to axis
42
+ create unit_data category-integer mapping and binds to axis
42
43
2. axis_info:
43
- sets ticks/locator and label /formatter
44
+ set ticks/locator and labels /formatter
44
45
3. convert:
45
- maps input category data to integers using unit_data
46
-
46
+ map input category data to integers using unit_data
47
47
"""
48
48
@staticmethod
49
49
def convert (value , unit , axis ):
@@ -55,7 +55,7 @@ def convert(value, unit, axis):
55
55
if isinstance (value , six .string_types ):
56
56
return vmap .get (value , None )
57
57
58
- vals = to_str_array (value )
58
+ vals = to_array (value )
59
59
for lab , loc in vmap .items ():
60
60
vals [vals == lab ] = loc
61
61
@@ -125,7 +125,7 @@ def __init__(self, data):
125
125
self .unit_data = None
126
126
self .units .default_units (data ,
127
127
self , sort = False )
128
-
128
+ self . loc2seq = dict ( zip ( self . unit_data . locs , self . unit_data . seq ))
129
129
self .vmin = min (self .unit_data .locs )
130
130
self .vmax = max (self .unit_data .locs )
131
131
@@ -139,6 +139,12 @@ def __call__(self, value, clip=None):
139
139
ret /= self .vmax
140
140
return np .ma .array (ret , mask = ~ mask )
141
141
142
+ def inverse (self , value ):
143
+ if not cbook .iterable (value ):
144
+ value = np .asarray (value )
145
+ vscaled = np .asarray (value ) * self .vmax
146
+ return [self .loc2seq [int (vs )] for vs in vscaled ]
147
+
142
148
143
149
def colors_from_categories (codings ):
144
150
"""
@@ -209,7 +215,7 @@ def update(self, new_data, sort=True):
209
215
210
216
def _set_seq_locs (self , data , value , sort ):
211
217
# magic to make it work under np1.6
212
- strdata = to_str_array (data )
218
+ strdata = to_array (data )
213
219
214
220
# np.unique makes dateframes work
215
221
if sort :
0 commit comments