I would like to display two histograms next to each other, using something like matplotlib's subplot function. This doesn't seem to work because plot_histogram() closes the figure.
It is possible to show a figure that has been closed - see this post. I tried this approach but it doesn't work (see code below). Does anyone know how to do this?
figs = []
for i in range(num):
counts = result.get_counts(circuits[i])
figs.append(plot_histogram(counts, title='here', bar_labels=True))
print(counts)
plt.subplot(121)
new_fig = plt.figure()
new_mngr = new_fig.canvas.manager
new_mngr.canvas.figure = figs[0]
fig.set_canvas(new_mngr.canvas)
plt.show(fig)
plt.subplot(122)
new_fig = plt.figure()
new_mngr = new_fig.canvas.manager
new_mngr.canvas.figure = figs[1]
fig.set_canvas(new_mngr.canvas)
plt.show(fig)
plot_histogram()
from closing the figure will fix this issue, then there is a way to do just that. If you go into the qiskit code toqiskit/visualization/counts_visualization.py
you will find theplot_histrogram()
method. Near the end of this method, you will see the conditional statementif fig: plt.close(fig)
. If you comment that out, it should stop automatically closing the figure when you callplot_histogram()
$\endgroup$