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_areauses 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¶
- 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.
QMplRendererdraws the die outline, so a plainax.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_TOLERANCEpixels converted to data units.
- Returns:
Component name, or None if the point hits nothing.
- Return type:
- find_component_bounds(components: list[str], zoom: float = 1.2)[source]¶
Find bounds of a set of components.
- highlight_all_components(show_pins: bool = True)[source]¶
Highlight and label every component in the design.
- highlight_components(component_names: list[str], show_pins: bool = True)[source]¶
Highlight a list of components.
- keyPressEvent(event)[source]¶
Nudge or rotate the selected component with the keyboard.
Lives here, not on the
QMainWindowPlotcontainer 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’ssetFocusabove).FigureCanvas(the base class) has its ownkeyPressEventfor 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 realQTest-injected key both ways: to this canvas (silently swallowed) and directly toQMainWindowPlot(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.
- refresh()[source]¶
Force refresh.
Does not replot renderer. Just mpl refresh.
Combines a synchronous
self.draw()withdraw_idle(): the latter schedules a redraw on the next Qt event-loop iteration, which catches the case whereself.draw()runs before the underlying axes have been laid out (a real bug observed whenhighlight_components()is called immediately after component instantiation — the rectangles + labels were appended to the axes but not visible until the user manually calledrefresh_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
- 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
- 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
QComponentstable callsgui.canvas.zoom_on_components([name]). Before this method was added that path raisedAttributeError(theMetalGUIHeadlessviewer always had it; the Qt canvas didn’t). 10 % padding is added around the combined bbox.