Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cliffords
Browse files Browse the repository at this point in the history
eendebakpt authored Sep 19, 2023
2 parents ff0ab80 + b27f33c commit 811a1c2
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions test/visualization/test_plotter_mpldrawer.py
Original file line number Diff line number Diff line change
@@ -118,9 +118,10 @@ def test_series_names_different_types(self, series_names: Dict[type, List[Any]])
"""

# Create Matplotlib axes that use a PNG backend. The default backend, FigureCanvasSVG, does not
# have `tostring_rgb()` which is needed to compute the difference between two figures in this
# have `buffer_rgba()` which is needed to compute the difference between two figures in this
# method. We need to set the axes as MplDrawer will use
# `qiskit_experiments.framework.matplotlib.get_non_gui_ax` by default; which uses an SVG backend.
plt.close("all")
plt.switch_backend("Agg")
axes = {}
for key in series_names.keys():
@@ -161,16 +162,12 @@ def test_series_names_different_types(self, series_names: Dict[type, List[Any]])
for plot_type in legend_plot_types:
plotter.enable_legend_for(series_name, plot_type)

# Generate figure and save to buffers for comparison. This requires a pixel backend, like AGG, so
# that `tostring_rgb()` is available.
# Generate figure and save to buffers for comparison.
figure_data = {}
for plotter_type, plotter in plotters.items():
figure = plotter.figure().figure
figure.canvas.draw()
figure_data[plotter_type] = np.frombuffer(
figure.canvas.tostring_rgb(),
dtype=np.uint8,
).reshape(figure.canvas.get_width_height() + (3,))
figure_data[plotter_type] = np.asarray(figure.canvas.buffer_rgba(), dtype=np.uint8)

# Compare root-mean-squared error between two images.
for (fig1_type, fig1), (fig2_type, fig2) in combinations(figure_data.items(), 2):

0 comments on commit 811a1c2

Please sign in to comment.