PlotCanvas

class PlotCanvas(*args: Any, **kwargs: Any)[source]

Main Plot canvas widget.

This class extends the FigureCanvas class.

Access with:

canvas = gui.canvas

Parameters:
  • design (QDesign) – The design.

  • parent (QMainWindowPlot) – The main window. Defaults to None.

  • logger (logging.Logger) – The logger. Defaults to None.

  • statusbar_label (str) – Statusbar label. Defaults to None.

Methods

__call__(*args: Any, **kwargs: Any) Any

Call self as a function.

__getitem__(key: Any) _MockObject
__len__() int
auto_scale()[source]

Automaticlaly scale.

clear_annotation()[source]

Clear the annotations.

Raises:

Exception – Error while clearing the annotations

clear_axis(ax: Axes = None)[source]

Clear an axis or clear all axes.

Parameters:

ax (plt.Axes) – Clear an axis, or if None, then clear all axes. Defaults to None.

debug_axis_config(ax=None)[source]

Print axis configuration for debugging.

find_component_bounds(components: List[str], zoom: float = 1.2)[source]

Find bounds of a set of components.

Parameters:
  • components (List[str]) – A list of component names

  • zoom (float) – Fraction to expand the bounding vbox by

Returns:

List of x,y coordinates defining the bounding box

Return type:

List

get_axis()[source]

Gets the current axis.

highlight_components(component_names: List[str])[source]

Highlight a list of components.

Parameters:

component_names (List[str]) – A list of component names

plot(clear=True, with_try=True)[source]

Render the plot.

Parameters:
  • clear (bool) – True to clear everything first. Defaults to True.

  • with_try (bool) – True to execute in a try-catch block. Defaults to True.

Raises:

Exception – Plotting error

refresh()[source]

Force refresh.

Does not replot renderer. Just mpl refresh.

Combines a synchronous self.draw() with draw_idle(): the latter schedules a redraw on the next Qt event-loop iteration, which catches the case where self.draw() runs before the underlying axes have been laid out (a real bug observed when highlight_components() is called immediately after component instantiation — the rectangles + labels were appended to the axes but not visible until the user manually called refresh_plot() again).

set_component(name: str)[source]

Shortcut to set a component in the component widget to be examined.

Parameters:

name (str) – Name of the component in the design

set_design(design: QDesign)[source]

Set the design.

Parameters:

design (QDesign) – the design

setup_figure_and_axes()[source]

Main setup from scratch.

setup_rendering()[source]

Line segment simplificatio: For plots that have line segments (e.g. typical line plots, outlines of polygons, etc.), rendering performance can be controlled by the path.simplify and path.simplify_threshold.

path_simplify:

When True, simplify paths by removing “invisible” points to reduce file size and increase rendering speed

path_simplify_threshold:

The threshold of similarity below which vertices will be removed in the simplification process

chuncksize:

0 to disable; values in the range 10000 to 100000 can improve speed slightly and prevent an Agg rendering failure when plotting very large data sets, especially if they are very gappy. It may cause minor artifacts, though. A value of 20000 is probably a good starting point.

https://matplotlib.org/3.1.1/tutorials/introductory/usage.html

style_axis(ax, num: int)[source]

Style the axis.

Parameters:
  • ax (axis) – The axis

  • num (int) – Not used

style_figure()[source]

Style a figure.

welcome_message()[source]

The GUI displays a message to let users know they are using Qiskit Metal.

zoom_on_components(component_names)[source]

Zoom the canvas to fit the bounding box of the given components.

Parameters:

component_names (List[str]) – Component names to frame.

Notes

Double-clicking a row in the QComponents table calls gui.canvas.zoom_on_components([name]). Before this method was added that path raised AttributeError (the MetalGUIHeadless viewer always had it; the Qt canvas didn’t). 10 % padding is added around the combined bbox.

zoom_to_rectangle(bounds: tuple, ax: Axes = None)[source]

Zoom to the specified rectangle.

Parameters:
  • bounds (tuple) – Tuple containing minx, miny, maxx, maxy values for the bounds of the series as a whole.

  • ax (Axes) – Does for all if none (default: {None})