pygsti.report.colormaps

Colormap and derived class definitions

Module Contents

Classes

Colormap

A color map which encapsulates a plotly colorscale with a normalization.

LinlogColormap

Colormap which combines a linear grayscale portion with a logarithmic color (by default red) portion.

DivergingColormap

A diverging color map

SequentialColormap

A sequential color map

PiecewiseLinearColormap

A piecewise-linear color map

Functions

_vnorm(x, vmin, vmax)

to_rgb_array(color_str)

Convert a color string, such as "rgb(0,255,128)" or "#00FF88" to a numpy array of length 3.

interpolate_plotly_colorscale(plotly_colorscale, normalized_value)

Evaluates plotly colorscale at a particular value.

pygsti.report.colormaps._vnorm(x, vmin, vmax)
pygsti.report.colormaps.to_rgb_array(color_str)

Convert a color string, such as “rgb(0,255,128)” or “#00FF88” to a numpy array of length 3.

Parameters

color_str (str) – A color string, e.g. “rgb(0,255,128)” or “#00FF88”.

Returns

numpy.ndarray

pygsti.report.colormaps.interpolate_plotly_colorscale(plotly_colorscale, normalized_value)

Evaluates plotly colorscale at a particular value.

This function linearly interpolates between the colors of a Plotly colorscale.

Parameters
  • plotly_colorscale (list) – A Plotly colorscale (list of [val, color]) elements where val is a float between 0 and 1, and color is any acceptable Plotly color value (e.g. rgb(0,100,255), #0033FF, etc.).

  • normalized_value (float) – The value (between 0 and 1) to compute the color for.

Returns

str – A string representation of the plotly color of the form “rgb(R,G,B)”.

class pygsti.report.colormaps.Colormap(rgb_colors, hmin, hmax, invalid_color=None)

Bases: object

A color map which encapsulates a plotly colorscale with a normalization.

This class also contains additional functionality such as the ability to compute the color corresponding to a particular value and extract matplotlib colormap and normalization objects.

Parameters
  • rgb_colors (list) – A list of [val, (R,G,B)] elements where val is a floating point number between 0 and 1 (plotly maps the post-‘normalized’ data linearly onto the interval [0,1] before mapping to a color), and R,`G`,and B are red, green, and blue floating point values in [0,1]. The color will be interpolated between the different “point” elements in this list.

  • hmin (float) – The minimum post-normalized values to be used for the heatmap. That is, hmin is the value (after normalize has been called) assigned the “0.0”-valued color in rgb_colors.

  • hmax (float) – The maximum post-normalized values to be used for the heatmap. That is, hmax is the value (after normalize has been called) assigned the “1.0”-valued color in rgb_colors.

  • invalid_color (tuple, optional) – If not None, an (R,G,B) tuple of values in [0,1] specifying the color to use for normalized values (which usually should be in [0,1]) that lie outside the [0,1] range of rgb_colors.

_brightness(self, r, g, b)
normalize(self, value)

Normalize value as it would be prior to linearly interpolating onto the [0,1] range of the color map.

In this case, no additional normalization is performed, so this function just returns value.

Parameters

value (float or numpy.ndarray) – The value to normalize.

Returns

float or numpy.ndarray

besttxtcolor(self, value)

Return the better text color, “black” or “white”, given an un-normalized value.

Parameters

value (float) – An un-normalized value.

Returns

str

create_plotly_colorscale(self)

Construct and return the plotly colorscale of this color map.

Returns

list – A list of [float_value, “rgb(R,G,B)”] items.

interpolate_color(self, value)

Retrieves the color at a particular colormap value.

This function linearly interpolates between the colors of a this colormap’s color scale

Parameters

value (float) – The value (before normalization) to compute the color for.

Returns

str – A string representation of the plotly color of the form “rgb(R,G,B)”.

create_matplotlib_norm_and_cmap(self)

Creates and returns normalization and colormap classes for matplotlib heatmap plots.

Returns

norm, cmap

class pygsti.report.colormaps.LinlogColormap(vmin, vmax, num_boxes, pcntle, dof_per_box, color='red')

Bases: Colormap

Colormap which combines a linear grayscale portion with a logarithmic color (by default red) portion.

The transition between these occurs at a point based on a percentile of chi^2 distribution.

Parameters
  • vmin (float) – The minium value of the data being colormapped.

  • vmax (float) – The maximum value of the data being colormapped.

  • num_boxes (int) – The number of boxes in the plot this colormap is being used with, so that pcntle gives a percentage of the worst box being “red”.

  • pcntle (float) – A number between 0 and 1 giving the probability that the worst box in the plot will be red. Typically a value of 0.05 is used.

  • dof_per_box (int) – The number of degrees of freedom represented by each box, so the expected distribution of each box’s values is chi^2_[dof_per_box].

  • color ({"red","blue","green","cyan","yellow","purple"}) – The color to use for the non-grayscale part of the color scale.

classmethod set_manual_transition_point(cls, vmin, vmax, trans, color='red')

Create a new LinlogColormap with a manually-specified transition point.

Parameters
  • vmin (float) – The minium value of the data being colormapped.

  • vmax (float) – The maximum value of the data being colormapped.

  • trans (float) – The transition-point value between the linear grayscale and logarithmic colorscale.

  • color ({"red","blue","green","cyan","yellow","purple"}) – the color to use for the non-grayscale part of the color scale.

Returns

LinlogColormap

normalize(self, value)

Scale value to a value between self.hmin and self.hmax (heatmap endpoints).

Parameters

value (float or numpy.ndarray) – The value to normalize.

Returns

float or numpy.ndarray

create_matplotlib_norm_and_cmap(self)

Creates and returns normalization and colormap classes for matplotlib heatmap plots.

Returns

norm, cmap

class pygsti.report.colormaps.DivergingColormap(vmin, vmax, midpoint=0.0, color='RdBu')

Bases: Colormap

A diverging color map

Parameters
  • vmin (float) – The minium value of the data being colormapped.

  • vmax (float) – The maximum value of the data being colormapped.

  • midpoint (float, optional) – The midpoint of the color scale.

  • color ({"RdBu"}) – What colors to use.

class pygsti.report.colormaps.SequentialColormap(vmin, vmax, color='whiteToBlack')

Bases: Colormap

A sequential color map

Parameters
  • vmin (float) – The minium value of the data being colormapped.

  • vmax (float) – The maximum value of the data being colormapped.

  • color ({"whiteToBlack", "blackToWhite"}) – What colors to use.

class pygsti.report.colormaps.PiecewiseLinearColormap(rgb_colors)

Bases: Colormap

A piecewise-linear color map

Parameters

rgb_colors (list) – A list of [val, (R,G,B)] elements where val is a floating point number (pre-normalization) of the value corresponding to the color given by R,`G`,and B: red, green, and blue floating point values in [0,1]. The color will be interpolated between the different “point” elements in this list.