supermarq.plotting ================== .. py:module:: supermarq.plotting Classes ------- .. autoapisummary:: supermarq.plotting.RadarAxesMeta Functions --------- .. autoapisummary:: supermarq.plotting.annotate_heatmap supermarq.plotting.heatmap supermarq.plotting.plot_benchmark supermarq.plotting.plot_correlations supermarq.plotting.plot_results supermarq.plotting.plot_volumetric_results supermarq.plotting.radar_factory Module Contents --------------- .. py:class:: RadarAxesMeta(*args: Any, **kwargs: Any) Bases: :py:obj:`matplotlib.projections.polar.PolarAxes` A helper class to generate feature-vector plots. .. py:method:: fill(*args: Any, closed: bool = True, **kwargs: Any) -> list[matplotlib.patches.Polygon] Method to override fill so that line is closed by default. :param args: Arguments to be passed to fill. :param closed: Optional parameter to close fill or not. Defaults to True. :param kwargs: Other desired keyworded arguments to be passed to fill. :returns: A list of `matplotlib.patches.Polygon`. .. py:method:: plot(*args: Any, **kwargs: Any) -> list[matplotlib.lines.Line2D] Overrides plot so that line is closed by default. :param args: Desired arguments for plotting. :param kwargs: Other desired keyword arguments for plotting. :returns: New closed lines. .. py:method:: set_varlabels(labels: list[str]) -> None Sets the spoke labels at the appropriate points on the radar plot. :param labels: The list of labels to apply. .. py:attribute:: RESOLUTION :value: 1 .. py:attribute:: frame :type: str .. py:attribute:: name :value: 'radar' .. py:attribute:: num_vars :type: int .. py:attribute:: theta :type: numpy.typing.NDArray[numpy.float_] .. py:function:: annotate_heatmap(im: matplotlib.image.AxesImage, data: numpy.typing.NDArray[numpy.float_] | None = None, valfmt: Any = '{x:.2f}', textcolors: tuple[str, str] = ('black', 'white'), threshold: float | None = None, **textkw: Any) -> list[matplotlib.text.Text] Annotate the given heatmap. :param im: The `AxesImage` to be labeled. :param data: Optional data used to annotate. If None, the image's data is used. :param valfmt: An optional format of the annotations inside the heatmap. This should either use the string format method, e.g. "$ {x:.2f}", or be a `matplotlib.ticker.Formatter`. :param textcolors: A pair of colors. The first is used for values below a threshold, the second for those above. Defaults to black and white respectively. :param threshold: An optional value in data units according to which of the colors from textcolors are applied. If None (the default) uses the middle of the colormap as separation. :param textkw: All other arguments are forwarded to each call to `text` used to create the text labels. :returns: List of the text annotations. .. py:function:: heatmap(data: numpy.typing.NDArray[numpy.float_], ax: matplotlib.axes.Axes, row_labels: list[str], col_labels: list[str], cbar_kw: dict[str, Any] | None = None, cbarlabel: str = '', **kwargs: Any) -> tuple[matplotlib.image.AxesImage, Any] Create a heatmap from a numpy array and two lists of labels. :param data: A 2D numpy array of shape (N, M). :param row_labels: A list or array of length N with the labels for the rows. :param col_labels: A list or array of length M with the labels for the columns. :param ax: An optional `matplotlib.axes.Axes` instance to which the heatmap is plotted. If not provided, use current axes or create a new one. :param cbar_kw: An optional dictionary with arguments to `matplotlib.Figure.colorbar`. :param cbarlabel: An optional label for the colorbar. :param kwargs: All other arguments are forwarded to `imshow`. :returns: The generated heatmap and the associated color bar. .. py:function:: plot_benchmark(title: str, labels: list[str], features: list[list[float]], show: bool = True, savefn: str | None = None, spoke_labels: list[str] | None = None, legend_loc: tuple[float, float] = (0.75, 0.85)) -> None Create a radar plot showing the feature vectors of the given benchmarks. :param title: The string title of the plot. :param labels: A list of string benchmark labels for the plot. :param features: A list of feature data in the format: [[features_1], [features_2], ...]]. :param show: Boolean flag to display the plot using `plt.show`. :param savefn: Path to save the plot, if `None`, the plot is not saved. :param spoke_labels: Optional labels for the feature vector dimensions. :param legend_loc: Optional argument to fine tune the legend placement. .. py:function:: plot_correlations(benchmark_features: dict[str, list[float]], device_scores: dict[str, float] | collections.abc.Iterable[dict[str, float]], feature_labels: list[str], device_name: str | list[str], savefn: str | None = None, show: bool = True) -> None Plot a correlation heatmap of the features for one or multiple devices. :param benchmark_features: A dictionary where the keys are benchmark names and the values are the list of feature values for that benchmark. :param device_scores: A dictionary of (benchmark name, score) pairs, or a list of such dictionaries. :param feature_labels: Feature names, should have the same length as the lists of feature values in `benchmark_features`. :param device_name: The name or list of names of quantum device(s) where the scores were obtained. :param savefn: Path to save the plot, if `None`, the plot is not saved. :param show: Display the plot using `plt.show`. .. py:function:: plot_results(scores: list[float], tick_labels: list[str], savefn: str | None = None, show: bool = True) -> None Plot a simple bar chart of the benchmark results. The ordering of scores and labels is assumed to be the same. :param scores: List of benchmark results. :param tick_labels: List of quantum device names. :param savefn: Path to save the plot, if `None`, the plot is not saved. :param show: Display the plot using `plt.show`. .. py:function:: plot_volumetric_results(benchmark_data: collections.abc.Iterable[tuple[int, int, float]], savefn: str | None = None, title: str | None = None, show: bool = True, xmax: float = 60, ymax: float = 7, rect_width: float = 1.5, rect_height: float = 0.2) -> None Plot the benchmark results on an (x, y) = (depth, qubits) axis. It is assumed that all of the given data was collected on a single device. Keyword arguments may need to be tweaked depending on the domain and range of benchmark data. :param benchmark_data: List of tuples containing (circuit depth, qubits, score) for each benchmark executed on a single device. :param savefn: Path to save the plot, if `None`, the plot is not saved. :param title: Optional title for the plot. :param show: Display the plot using `plt.show`. :param xmax: The rightmost limit of the x axis. :param ymax: The uppermost limit of the y axis. :param rect_width: The width of the rectangles. :param rect_height: The height of the rectangles. .. py:function:: radar_factory(num_vars: int) -> numpy.typing.NDArray[numpy.float_] Create a radar chart with `num_vars` axes. (https://matplotlib.org/stable/gallery/specialty_plots/radar_chart.html) This function creates a `RadarAxes` projection and registers it. :param num_vars: Number of variables for radar chart. :returns: A list of evenly spaced angles.