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

Class StrCategoryFormatter

lib/matplotlib/category.py:139–166  ·  view source on GitHub ↗

String representation of the data at every tick.

Source from the content-addressed store, hash-verified

137
138
139class StrCategoryFormatter(ticker.Formatter):
140 """String representation of the data at every tick."""
141 def __init__(self, units_mapping):
142 """
143 Parameters
144 ----------
145 units_mapping : dict
146 Mapping of category names (str) to indices (int).
147 """
148 self._units = units_mapping
149
150 def __call__(self, x, pos=None):
151 # docstring inherited
152 return self.format_ticks([x])[0]
153
154 def format_ticks(self, values):
155 # docstring inherited
156 r_mapping = {v: self._text(k) for k, v in self._units.items()}
157 return [r_mapping.get(round(val), '') for val in values]
158
159 @staticmethod
160 def _text(value):
161 """Convert text values into utf-8 or ascii strings."""
162 if isinstance(value, bytes):
163 value = value.decode(encoding='utf-8')
164 elif not isinstance(value, str):
165 value = str(value)
166 return value
167
168
169class UnitData:

Callers 1

axisinfoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…