Esempio n. 1
0
    def process(
        self,
        dataIn: Optional[DataDictBase] = None
    ) -> Optional[Dict[str, Optional[DataDictBase]]]:
        if super().process(dataIn=dataIn) is None:
            return None
        assert dataIn is not None
        data = dataIn.copy()

        if self.scale_unit_option != ScaleUnitsOption.never:
            for name, data_item in data.data_items():
                prefix, selected_scale = find_scale_and_prefix(
                    data_item['values'], data_item["unit"])
                data_item["unit"] = prefix + data_item["unit"]
                data_item['values'] = data_item['values'] * 10**(
                    -selected_scale)

        return dict(dataOut=data)
Esempio n. 2
0
def _make_rescaled_ticks_and_units(
    data_dict: DSPlotData,
) -> Tuple[matplotlib.ticker.FuncFormatter, str]:
    """
    Create a ticks formatter and a new label for the data that is to be used
    on the axes where the data is plotted.

    For example, if values of data are all "nano" in units of volts "V",
    then the plot might be more readable if the tick formatter would show
    values like "1" instead of "0.000000001" while the units in the axis label
    are changed from "V" to "nV" ('n' is for 'nano').

    The units for which unit prefixes are added can be found in
    `qcodes.utils.plotting._UNITS_FOR_RESCALING`. For all other units
    an exponential scaling factor is added to the label i.e.
    `(10^3 x e^2/hbar)`.

    Args:
        data_dict: A dictionary of the following structure
            {
                'data': <1D numpy array of points>,
                'name': <name of the parameter>,
                'label': <label of the parameter or ''>,
                'unit': <unit of the parameter or ''>
            }

    Returns:
        A tuple with the ticks formatter (matlplotlib.ticker.FuncFormatter) and
        the new label.
    """
    unit = data_dict['unit']

    maxval = np.nanmax(np.abs(data_dict['data']))
    prefix, selected_scale = find_scale_and_prefix(maxval, unit)

    new_unit = prefix + unit
    label = _get_label_of_data(data_dict)
    new_label = _make_axis_label(label, new_unit)

    scale_factor = 10**(-selected_scale)
    ticks_formatter = FuncFormatter(
        partial(_scale_formatter, factor=scale_factor))

    return ticks_formatter, new_label