diff --git a/test/visualization/test_plotter_mpldrawer.py b/test/visualization/test_plotter_mpldrawer.py index b39f9fcd4d..a3fc730659 100644 --- a/test/visualization/test_plotter_mpldrawer.py +++ b/test/visualization/test_plotter_mpldrawer.py @@ -121,6 +121,7 @@ def test_series_names_different_types(self, series_names: Dict[type, List[Any]]) # have `tostring_rgb()` 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(): @@ -167,10 +168,7 @@ def test_series_names_different_types(self, series_names: Dict[type, List[Any]]) 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):