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.

Attributes

CLICK_PIXEL_TOLERANCE = 3

A press and release within this many pixels counts as a click rather than a drag. Matches the threshold _zoom_area uses to ignore accidental rubber-band drags, so pan and select agree on the boundary.

NUDGE_COARSE_FACTOR = 10.0

Multipliers for the modifier keys. Shift coarsens, Alt refines – the convention every drawing tool uses.

NUDGE_FINE_FACTOR = 0.1
NUDGE_STEP_MM = 0.05

Grid step for one arrow-key press, in millimetres.

PICK_PIXEL_TOLERANCE = 5

Click tolerance in pixels, converted to data units at query time. Routes are zero-width paths, so an exact point-in-polygon test would make them practically unclickable.

ROTATE_FINE_DEG = 15.0
ROTATE_STEP_DEG = 90.0

Rotation step for one bracket-key press, in degrees. 90 is the common case (most qlibrary layouts are built on a 90-degree grid); Shift gives finer control for anything off-grid.

Methods

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

Call self as a function.

__getitem__(key: Any) _MockObject
__len__() int
auto_scale(include_chip: bool = False)[source]

Frame the design.

Parameters:

include_chip (bool) – Frame the whole chip rather than just the components. Defaults to False.

Notes

The default deliberately ignores the chip. QMplRenderer draws the die outline, so a plain ax.autoscale() frames the full chip – a default 9x6mm die around a 0.65mm transmon leaves the component an unreadable speck. The tutorials were all written assuming the chip is ignored.

Falls back to framing everything when no component has usable bounds, so an empty design still shows the chip rather than an arbitrary window.

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.

component_at_point(x: float, y: float, tolerance: float = None)[source]

Return the name of the component under a data-space point.

Parameters:
  • x (float) – X in data (mm) coordinates.

  • y (float) – Y in data (mm) coordinates.

  • tolerance (float) – Search radius in data units. Defaults to PICK_PIXEL_TOLERANCE pixels converted to data units.

Returns:

Component name, or None if the point hits nothing.

Return type:

str

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_all_components(show_pins: bool = True)[source]

Highlight and label every component in the design.

Parameters:

show_pins (bool) – Also draw pin arrows and pin names. Defaults to True.

Returns:

Number of components labelled.

Return type:

int

highlight_components(component_names: list[str], show_pins: bool = True)[source]

Highlight a list of components.

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

  • show_pins (bool) – Draw pin arrows and pin names alongside the component name. Turn off on dense chips, where per-pin labels swamp the component labels. Defaults to True.

keyPressEvent(event)[source]

Nudge or rotate the selected component with the keyboard.

Lives here, not on the QMainWindowPlot container that used to own this logic, because this canvas – not its parent – is the widget that actually holds keyboard focus after a click-select (see _on_pick_release’s setFocus above). FigureCanvas (the base class) has its own keyPressEvent for matplotlib’s built-in shortcuts and does not propagate unhandled keys to the parent, so a handler on the container was simply never reached – confirmed by sending a real QTest-injected key both ways: to this canvas (silently swallowed) and directly to QMainWindowPlot (moved the component correctly). Deliberately keyboard-only: dragging would have to share the left mouse button with panning and needs a live preview, and a rebuild per mouse-move is far too slow.

Parameters:

event (QKeyEvent) – The key event.

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})