Drawing Circuits
Text drawing options: reversed qubit order, hiding barriers, and bundling classical registers.
The qc.draw("text") method returns a drawing in Unicode characters that can be printed in any terminal or notebook, without matplotlib. The main options:
reverse_bits=True puts the highest-index qubit at the top, so the order of the lines from top to bottom matches the order of the bits in the printed string $q_{n-1}\dots q_0$; this helps when comparing the drawing with textbooks that use Big-endian ordering.
plot_barriers=False hides Barriers. A barrier is not a physical operation; it stops the transpiler from merging or moving gates across it, and it is also used to split the circuit visually into stages.
cregbundle=True bundles the bits of the classical register into a single line labelled with its size (such as c: 3/), with numbers showing which bit receives each measurement.
The example is a three-qubit GHZ circuit: H, then a chain of CNOTs, then a barrier, then measurement. In the reversed drawing the circuit is the same, but the lines are shown from $q_2$ to $q_0$. You can also use output="mpl" for a matplotlib drawing or "latex", but both need extra packages and an interface for displaying images. For long circuits the text drawing wraps lines automatically, which can be controlled with the fold parameter.
Requirements: pip install qiskit qiskit-aer. The code runs on your machine or in Colab, not inside WordPress.
Code
from qiskit import QuantumCircuit
qc = QuantumCircuit(3, 3)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)
qc.barrier()
qc.measure(range(3), range(3))
print(qc.draw("text"))
print(qc.draw("text", reverse_bits=True))
print(qc.draw("text", plot_barriers=False, cregbundle=True))
Line-by-line code explanation
| Line | Explanation |
|---|---|
| 1 | Import the circuit class. |
| 3 | A circuit with three qubits and three bits. |
| 4-6 | Prepare a GHZ state: a Hadamard then a chain of CNOTs. |
| 7 | A barrier to separate preparation from measurement visually and to prevent reordering. |
| 8 | Measure the three qubits into the three bits. |
| 10 | The default text drawing (q0 at the top). |
| 11 | The drawing in reversed order (q2 at the top). |
| 12 | Hide barriers and bundle the classical register. |
Expected output (from an actual run)
┌───┐ ░ ┌─┐
q_0: ┤ H ├──■────────░─┤M├──────
└───┘┌─┴─┐ ░ └╥┘┌─┐
q_1: ─────┤ X ├──■───░──╫─┤M├───
└───┘┌─┴─┐ ░ ║ └╥┘┌─┐
q_2: ──────────┤ X ├─░──╫──╫─┤M├
└───┘ ░ ║ ║ └╥┘
c: 3/═══════════════════╩══╩══╩═
0 1 2
┌───┐ ░ ┌─┐
q_2: ──────────┤ X ├─░───────┤M├
┌───┐└─┬─┘ ░ ┌─┐└╥┘
q_1: ─────┤ X ├──■───░────┤M├─╫─
┌───┐└─┬─┘ ░ ┌─┐└╥┘ ║
q_0: ┤ H ├──■────────░─┤M├─╫──╫─
└───┘ ░ └╥┘ ║ ║
c: 3/═══════════════════╩══╩══╩═
0 1 2
┌───┐ ┌─┐
q_0: ┤ H ├──■────────┤M├──────
└───┘┌─┴─┐ └╥┘┌─┐
q_1: ─────┤ X ├──■────╫─┤M├───
└───┘┌─┴─┐ ║ └╥┘┌─┐
q_2: ──────────┤ X ├──╫──╫─┤M├
└───┘ ║ ║ └╥┘
c: 3/═════════════════╩══╩══╩═
0 1 2
The output is deterministic.
Try it yourself
Related topics
References
- IBM Quantum (2025). Qiskit SDK API documentation. IBM Quantum Documentation quantum.cloud.ibm.com
