qcodes.utils.plotting

This file holds plotting utility functions that are independent of the dataset from which to be plotted. For the current dataset see qcodes.dataset.plotting For the legacy dataset see qcodes.plots

qcodes.utils.plotting.apply_auto_color_scale(colorbar: matplotlib.colorbar.Colorbar, data_array: Optional[numpy.ndarray] = None, cutoff_percentile: Union[Tuple[float, float], float] = (50, 50), color_over: Optional[Any] = 'Magenta', color_under: Optional[Any] = 'Cyan') None[source]

Sets the color limits such that outliers are disregarded.

This method combines the automatic color scaling from auto_range_iqr() with the color bar setting from apply_color_scale_limits(). If you want to adjust the color scale based on the configuration file qcodesrc.json, use auto_color_scale_from_config(), which is used In qcodes.dataset.plotting.plot_by_id().

Parameters
  • colorbar – The matplotlib colorbar to which to apply.

  • data_array – The data on which the statistical analysis is based. If left out, the data associated with the colorbar is used

  • cutoff_percentile – Percentile of data that may maximally be clipped on both sides of the distribution. If given a tuple (a,b) the percentile limits will be a and 100-b.

  • color_over – Matplotlib color representing the datapoints clipped by the upper limit.

  • color_under – Matplotlib color representing the datapoints clipped by the lower limit.

Raises

RuntimeError – If not mesh data.

qcodes.utils.plotting.apply_color_scale_limits(colorbar: matplotlib.colorbar.Colorbar, new_lim: Tuple[Optional[float], Optional[float]], data_lim: Optional[Tuple[float, float]] = None, data_array: Optional[numpy.ndarray] = None, color_over: Optional[Any] = 'Magenta', color_under: Optional[Any] = 'Cyan') None[source]

Applies limits to colorscale and updates extend.

This function applies the limits new_lim to the heatmap plot associated with the provided colorbar, updates the colorbar limits, and also adds the colorbar clipping indicators in form of small triangles on the top and bottom of the colorbar, according to where the limits are exceeded.

Parameters
  • colorbar – The actual colorbar to be updated.

  • new_lim – 2-tuple of the desired minimum and maximum value of the color scale. If any is None it will be left unchanged.

  • data_lim – 2-tuple of the actual minimum and maximum value of the data. If left out the minimum and maximum are deduced from the provided data, or the data associated with the colorbar.

  • data_array – Numpy array containing the data to be considered for scaling. Must be left out if data_lim is provided. If neither is provided the data associated with the colorbar is used.

  • color_over – Matplotlib color representing the datapoints clipped by the upper limit.

  • color_under – Matplotlib color representing the datapoints clipped by the lower limit.

Raises
  • RuntimeError – If not received mesh data. Or if you specified both

  • data_lim

qcodes.utils.plotting.auto_color_scale_from_config(colorbar: matplotlib.colorbar.Colorbar, auto_color_scale: Optional[bool] = None, data_array: Optional[numpy.ndarray] = None, cutoff_percentile: Optional[Union[Tuple[float, float], float]] = (50, 50), color_over: Optional[Any] = None, color_under: Optional[Any] = None) None[source]

Sets the color limits such that outliers are disregarded, depending on the configuration file qcodesrc.json. If optional arguments are passed the config values are overridden.

Parameters
  • colorbar – The colorbar to scale.

  • auto_color_scale – Enable smart colorscale. If False nothing happens. Default value is read from config.plotting.auto_color_scale.enabled.

  • data_array – Numpy array containing the data to be considered for scaling.

  • cutoff_percentile – The maxiumum percentile that is cut from the data. Default value is read from config.plotting.auto_color_scale.cutoff_percentile.

  • color_over – Matplotlib color representing the datapoints clipped by the upper limit. Default value is read from config.plotting.auto_color_scale.color_over.

  • color_under – Matplotlib color representing the datapoints clipped by the lower limit. Default value is read from config.plotting.auto_color_scale.color_under.

qcodes.utils.plotting.auto_range_iqr(data_array: numpy.ndarray, cutoff_percentile: Union[Tuple[float, float], float] = (50, 50)) Tuple[float, float][source]

Get the min and max range of the provided array that excludes outliers following the IQR rule.

This function computes the inter-quartile-range (IQR), defined by Q3-Q1, i.e. the percentiles for 75% and 25% of the distribution. The region without outliers is defined by [Q1-1.5*IQR, Q3+1.5*IQR].

Parameters
  • data_array – Numpy array of arbitrary dimension containing the statistical data.

  • cutoff_percentile – Percentile of data that may maximally be clipped on both sides of the distribution. If given a tuple (a,b) the percentile limits will be a and 100-b.

Returns

region limits [vmin, vmax]

qcodes.utils.plotting.find_scale_and_prefix(data: numpy.ndarray, unit: str) Tuple[str, int][source]

Given a numpy array of data and a unit find the best engineering prefix and matching scale that best describes the data.

The units for which unit prefixes are added can be found in _UNITS_FOR_RESCALING. For all other units the prefix is an exponential scaling factor e.g. 10^3. If no unit is given (i.e. an empty string) no scaling is performed.

Parameters
  • data – A numpy array of data.

  • unit – The unit the data is measured in. Should not contain a prefix already.

Returns

tuple of prefix and exponential scale