IndexTranslator¶
-
class
qf_lib.plotting.helpers.index_translator.
IndexTranslator
(labels_to_locations_dict: Mapping[str, numbers.Number] = None)[source]¶ Bases:
object
Object which automatically translates label-indexed data into number-indexed data.
- Parameters
labels_to_locations_dict (Mapping[str, Number]) – Contains a mapping from labels to numbers (used as index values for plotting). Must have unique keys and unique values.
Methods
inv_translate
(translated_values, …)Translates numeric coordinate into label.
setup_ticks_and_labels
(chart)Setups ticks’ locations and labels in the given chart if it used IndexTranslator.
translate
(values, Sequence[str]])Translates label into numeric coordinate.
-
inv_translate
(translated_values: Union[numbers.Number, Sequence[numbers.Number]]) → List[str][source]¶ Translates numeric coordinate into label. Requirement: the Translator must be familiar with mapping the label into numeric coordinate (either the translate must have been called or the labels_to_locations_dict must contain a proper entry).
- Parameters
translated_values – numeric values to be changed into labels (e.g. [0.0, 1.0, 2.0])
- Returns
labels corresponding to numeric values
- Return type
labels
-
classmethod
setup_ticks_and_labels
(chart: Chart)[source]¶ Setups ticks’ locations and labels in the given chart if it used IndexTranslator.
-
translate
(values: Union[str, Sequence[str]]) → List[numbers.Number][source]¶ Translates label into numeric coordinate. If the translation is done for the first time for this value it may modify the state of the translator (it may introduce a new translation).
- Parameters
values – values to be translated (e.g. [“SPY”, “GOOGL”])
- Returns
value translated into numeric coordinate
- Return type
translated values