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

Class StrCategoryConverter

lib/matplotlib/category.py:26–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
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):
63 """
64 Set the default axis ticks and labels.
65
66 Parameters
67 ----------
68 unit : `.UnitData`
69 object string unit information for value
70 axis : `~matplotlib.axis.Axis`
71 axis for which information is being set
72
73 .. note:: *axis* is not used
74
75 Returns
76 -------
77 `~matplotlib.units.AxisInfo`
78 Information to support default tick labeling
79
80 """
81 StrCategoryConverter._validate_unit(unit)
82 # locator and formatter take mapping dict because
83 # args need to be pass by reference for updates

Callers 2

test_explicit_converterFunction · 0.90
category.pyFile · 0.85

Calls

no outgoing calls

Tested by 1

test_explicit_converterFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…