0
$\begingroup$

I am running certain circuits in the Aer simulators and I need to present them nicely. I prefer to use the options provided by Seaborn. How can I transfer my Aer data, e.g. histograms, to Seaborn?

For example, running the simple circuit:

meas = QuantumCircuit(3, 3)
meas.barrier(range(3))
 
meas.measure(range(3), range(3))


circ.add_register(meas.cregs[0])
qc = circ.compose(meas)

qc.draw()

and using Aer

backend_sim = Aer.get_backend('qasm_simulator')
job_sim = backend_sim.run(transpile(qc, backend_sim), shots=1024)
result_sim = job_sim.result()
counts = result_sim.get_counts(qc)
from qiskit.visualization import plot_histogram
plot_histogram(counts)

yields:

enter image description here

However, I prefer to use the stylistic options of Seaborn instead in order to make nice plots.

$\endgroup$

1 Answer 1

1
$\begingroup$

The counts variable in your code example is just a dictionary with bit strings for keys and the count of times that bit string was returned from the execution of the circuit. Something like: {"000": 513, "111": 467}. If you want to make your own plot with seaborn you can just access the data from the Counts object directly. For example, something like:

import matplotlib.pyplot as plt
import seaborn

counts = {"000": 513, "111": 467}
seaborn.barplot(list(counts.keys()), list(counts.values()))

yields:

seaborn bar chart

That being said plot_histogram function does have some style arguments including for color: https://qiskit.org/documentation/stubs/qiskit.visualization.plot_histogram.html that may enable you to get the output visualization you want from the function.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.