I'm using Qiskit in Visual Studio 2019. I want to draw quantum circuits, but it only shows their sizes with text instead of figures. The output on the interactive window is like this.

>>> from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
   ...: import numpy as np
   ...: %matplotlib inline

In [2]: qr = QuantumRegister(1)
   ...: cr = ClassicalRegister(1)
   ...: circuit = QuantumCircuit(qr, cr)
   ...: circuit.h(qr[0])
Out [2]: <qiskit.extensions.standard.h.HGate at 0x2c9b16b8e80>

In [3]: circuit.draw(output="mpl")
Out [3]: <Figure size 240.8x138.46 with 1 Axes>

Is there any way to draw circuits correctly, or is it simply that Qiskit doesn't work in Visual Studio?

<edited> the qiskit version

In [6]: print(qiskit.__version__)
  • $\begingroup$ For me it works in the separate terminal in visual studio (on wsl) not in the interactive window. Do you know the version? print(qiskit.__version__) $\endgroup$
    – Bram
    Jun 6, 2019 at 11:56

3 Answers 3


qc.draw can output the figure to matplotlib. Simply call plt.show() at the end.

import matplotlib.pyplot as plt 
from qiskit import QuantumCircuit

qc = QuantumCircuit(3, 3)

If you are in the interactive window, it probably works similarly to Jupyter Notebooks. I would run %matplotlib inline, and then try calling circuit.draw(output='mpl') again.

You could also try running the line circuit.draw(output='mpl') twice, as that also will render the Figure in Jupyter Notebookes.

  • $\begingroup$ I don't understand what you mean. Is that running# import anything I need<br/> # define the circuit<br/> %matplotlib inline<br/> circuit.draw(output='mpl') and # import anything I need<br/> # define the circuit<br/> circuit.draw(output='mpl')<br/> circuit.draw(output='mpl')? Neither work for me. $\endgroup$
    – Lemonade
    Jun 11, 2019 at 10:43
  • $\begingroup$ How do I start a new line btw? It looks awful without any. $\endgroup$
    – Lemonade
    Jun 11, 2019 at 10:52
  • $\begingroup$ My answer is assuming that the interactive window in Visual Studios works similar to coding in Jupyter Notebooks. Example code of what I meant is: %matplotlib inline import qiskit from qiskit import QuantumCircuit qc = QuantumCircuit(5, 5) qc.draw(output='mpl') This is the most basic example without any gates, but it should still render the empty circuit Figure $\endgroup$ Jun 11, 2019 at 13:42
  • $\begingroup$ Also not sure about starting new lines. Each of those code blocks is a separate line though. $\endgroup$ Jun 11, 2019 at 13:46
  • $\begingroup$ Still not working. But I found I can draw figures in Jupyter Notebooks, so it might be better using Jupyter Notebooks. $\endgroup$
    – Lemonade
    Jun 17, 2019 at 3:58

Add interactive :

qubit.draw(output='mpl', fold=50, interactive= True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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