6

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__)
0.8.1
Lemonade
  • 61
  • 1
  • 3

3 Answers3

4

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) qc.draw(output="mpl") plt.show()

2

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.

0

Add interactive :

qubit.draw(output='mpl', fold=50, interactive= True)
Ron Cohen
  • 1,512
  • 6
  • 24