|
23 | 23 | class StrCategoryConverter(units.ConversionInterface):
|
24 | 24 | @staticmethod
|
25 | 25 | def convert(value, unit, axis):
|
26 |
| - """Converts strings in value to floats using |
| 26 | + """Convert strings in value to floats using |
27 | 27 | mapping information store in the unit object.
|
28 | 28 |
|
29 | 29 | Parameters
|
30 | 30 | ----------
|
31 | 31 | value : string or iterable
|
32 |
| - value or list of values to be converted |
33 |
| - unit : :class:`.UnitData` |
34 |
| - object string unit information for value |
35 |
| - axis : :class:`~matplotlib.Axis.axis` |
36 |
| - axis on which the converted value is plotted |
| 32 | + Value or list of values to be converted. |
| 33 | + unit : `.UnitData` |
| 34 | + An object mapping strings to integers. |
| 35 | + axis : `~matplotlib.axis.Axis` |
| 36 | + axis on which the converted value is plotted. |
| 37 | +
|
| 38 | + .. note:: *axis* is unused. |
37 | 39 |
|
38 | 40 | Returns
|
39 | 41 | -------
|
40 |
| - mapped_ value : float or ndarray[float] |
41 |
| -
|
42 |
| - .. note:: axis is not used in this function |
| 42 | + mapped_value : float or ndarray[float] |
43 | 43 | """
|
| 44 | + if unit is None: |
| 45 | + raise ValueError( |
| 46 | + 'Missing category information for StrCategoryConverter; ' |
| 47 | + 'this might be caused by unintendedly mixing categorical and ' |
| 48 | + 'numeric data') |
| 49 | + |
44 | 50 | # dtype = object preserves numerical pass throughs
|
45 | 51 | values = np.atleast_1d(np.array(value, dtype=object))
|
46 | 52 |
|
@@ -190,7 +196,7 @@ def update(self, data):
|
190 | 196 | self._mapping[val] = next(self._counter)
|
191 | 197 |
|
192 | 198 |
|
193 |
| -# Connects the convertor to matplotlib |
| 199 | +# Register the converter with Matplotlib's unit framework |
194 | 200 | units.registry[str] = StrCategoryConverter()
|
195 | 201 | units.registry[np.str_] = StrCategoryConverter()
|
196 | 202 | units.registry[bytes] = StrCategoryConverter()
|
|
0 commit comments