pygsti.report.mpl_colormaps

Plotly-to-Matplotlib conversion functions.

Module Contents

Classes

MplLinLogNorm

Matplotlib version of lin-log colormap normalization

Functions

mpl_make_linear_norm(vmin, vmax, clip=False)

Create a linear matplotlib normalization

mpl_make_linear_cmap(rgb_colors, name=None)

Make a color map that simply linearly interpolates between a set of colors in RGB space.

mpl_besttxtcolor(x, cmap, norm)

Determinining function for whether text should be white or black

mpl_process_lbl(lbl, math=False)

Process a (plotly-compatible) text label lbl to matplotlb text.

mpl_process_lbls(lbl_list)

Process a list of plotly labels into matplotlib ones

mpl_color(plotly_color)

Convert a plotly color name to a matplotlib compatible one.

plotly_to_matplotlib(pygsti_fig, save_to=None, fontsize=12, prec='compacthp', box_labels_font_size=6)

Convert a pygsti (plotly) figure to a matplotlib figure.

special_keyplot(pygsti_fig, save_to, fontsize)

Create a plot showing the layout of a single sub-block of a goodness-of-fit box plot.

class pygsti.report.mpl_colormaps.MplLinLogNorm(linlog_colormap, clip=False)

Bases: matplotlib.colors.Normalize

Matplotlib version of lin-log colormap normalization

Parameters
  • linlog_colormap (LinlogColormap) – pyGSTi linear-logarithmic color map to base this colormap off of.

  • clip (bool, optional) – Whether clipping should be performed. See matplotlib.colors.Normalize.

inverse(self, value)

Inverse of __call__ as per matplotlib spec.

Parameters

value (float or numpy.ndarray) – Color-value to invert back.

Returns

float or numpy.ndarray

__call__(self, value, clip=None)

Normalize value data in the [vmin, vmax] interval into the [0.0, 1.0] interval and return it.

Parameters
  • value – Data to normalize.

  • clip (bool) – If None, defaults to self.clip (which defaults to False).

Notes

If not already initialized, self.vmin and self.vmax are initialized using self.autoscale_None(value).

pygsti.report.mpl_colormaps.mpl_make_linear_norm(vmin, vmax, clip=False)

Create a linear matplotlib normalization

Parameters
  • vmin (float) – Minimum mapped color value.

  • vmax (float) – Maximum mapped color value.

  • clip (bool, optional) – Whether clipping should be performed. See matplotlib.colors.Normalize.

Returns

matplotlib.colors.Normalize

pygsti.report.mpl_colormaps.mpl_make_linear_cmap(rgb_colors, name=None)

Make a color map that simply linearly interpolates between a set of colors in RGB space.

Parameters
  • rgb_colors (list) – Each element is a (value, (r, g, b)) tuple specifying a value and an RGB color. Both value and r, g, and b should be floating point numbers between 0 and 1.

  • name (string, optional) – A name for the colormap. If not provided, a name will be constructed from an random integer.

Returns

cmap

pygsti.report.mpl_colormaps.mpl_besttxtcolor(x, cmap, norm)

Determinining function for whether text should be white or black

Parameters
  • x (float) – Value of the cell in question

  • cmap (matplotlib colormap) – Colormap assigning colors to the cells

  • norm (matplotlib normalizer) – Function to map cell values to the interval [0, 1] for use by a colormap

Returns

{“white”,”black”}

pygsti.report.mpl_colormaps.mpl_process_lbl(lbl, math=False)

Process a (plotly-compatible) text label lbl to matplotlb text.

Parameters
  • lbl (str) – A text label to process.

  • math (bool, optional) – Whether math-formatting (latex) should be used.

Returns

str

pygsti.report.mpl_colormaps.mpl_process_lbls(lbl_list)

Process a list of plotly labels into matplotlib ones

Parameters

lbl_list (list) – A list of string-valued labels to process.

Returns

list – the processed labels (strings).

pygsti.report.mpl_colormaps.mpl_color(plotly_color)

Convert a plotly color name to a matplotlib compatible one.

Parameters

plotly_color (str) – A plotly color value, e.g. “#FF0023” or “rgb(0,255,128)”.

Returns

str

pygsti.report.mpl_colormaps.plotly_to_matplotlib(pygsti_fig, save_to=None, fontsize=12, prec='compacthp', box_labels_font_size=6)

Convert a pygsti (plotly) figure to a matplotlib figure.

Parameters
  • pygsti_fig (ReportFigure) – A pyGSTi figure.

  • save_to (str) – Output filename. Extension determines type. If None, then the matplotlib figure is returned instead of saved.

  • fontsize (int, optional) – Base fontsize to use for converted figure.

  • prec (int or {"compact","compacth"}) – Digits of precision to include in labels.

  • box_labels_font_size (int, optional) – The size for labels on the boxes. If 0 then no labels are put on the boxes

Returns

matplotlib.Figure – Matplotlib figure, unless save_to is not None, in which case the figure is closed and None is returned.

pygsti.report.mpl_colormaps.special_keyplot(pygsti_fig, save_to, fontsize)

Create a plot showing the layout of a single sub-block of a goodness-of-fit box plot.

Parameters
  • pygsti_fig (ReportFigure) – The pyGSTi figure to process.

  • save_to (str) – Filename to save to.

  • fontsize (int) – Fone size to use

Returns

matplotlib.Figure