MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / convert

Method convert

lib/matplotlib/category.py:28–59  ·  view source on GitHub ↗

Convert strings in *value* to floats using mapping information stored in the *unit* object. Parameters ---------- value : str or iterable Value or list of values to be converted. unit : `.UnitData` An object mapping strings to

(value, unit, axis)

Source from the content-addressed store, hash-verified

26class StrCategoryConverter(units.ConversionInterface):
27 @staticmethod
28 def convert(value, unit, axis):
29 """
30 Convert strings in *value* to floats using mapping information stored
31 in the *unit* object.
32
33 Parameters
34 ----------
35 value : str or iterable
36 Value or list of values to be converted.
37 unit : `.UnitData`
38 An object mapping strings to integers.
39 axis : `~matplotlib.axis.Axis`
40 The axis on which the converted value is plotted.
41
42 .. note:: *axis* is unused.
43
44 Returns
45 -------
46 float or `~numpy.ndarray` of float
47 """
48 if unit is None:
49 raise ValueError(
50 'Missing category information for StrCategoryConverter; '
51 'this might be caused by unintendedly mixing categorical and '
52 'numeric data')
53 StrCategoryConverter._validate_unit(unit)
54 # dtype = object preserves numerical pass throughs
55 values = np.atleast_1d(np.array(value, dtype=object))
56 # force an update so it also does type checking
57 unit.update(values)
58 s = np.vectorize(unit._mapping.__getitem__, otypes=[float])(values)
59 return s if not cbook.is_scalar_or_string(value) else s[0]
60
61 @staticmethod
62 def axisinfo(unit, axis):

Callers

nothing calls this directly

Calls 2

_validate_unitMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected