0

System Informations

Qiskit version: 0.17.0
Python version: 3.7.7
Operating system: Windows 10 home x64

What is the current behavior?

I am using spyder 4.1.1 on Anaconda and any time I try to plot data it does not show up. The code runs with no errors but the plot it self does not appear anywhere.

Steps to reproduce the problem

Running the code listed below which is from the IBMQ website:

import numpy 
import qiskit as qc 
from qiskit import QuantumCircuit, execute, Aer
import matplotlib
from qiskit.visualization import plot_state_city

circ = qc.QuantumCircuit(3)

circ.h(0)
circ.cx(0,1)
circ.cx(0,2)
print(circ.draw())
backend = Aer.get_backend('statevector_simulator')
job = execute(circ, backend)
result = job.result()
outputstate = result.get_statevector(circ, decimals=3)
print(outputstate)
plot_state_city(outputstate)

What is the expected behavior?

for the plot state city plot to show up in the console or somewhere else

Suggested solutions

I tried using both matplotlib.pylot.show() and matplotlib.pyplot.draw()

tinjinkin
  • 3
  • 2

5 Answers5

1

Try follow the instructions under "Spyder plots in separate windows" here. Then you can also call circ.draw(output='mpl') to draw the circuit in a window. Hope this helps.

kgi
  • 26
  • 3
1

To print your circuit, you have to type print(name of the circuit) so in your case type print(circ).

lisa
  • 13
  • 2
0

This may be because the plots don't show in spyder by default. If you run this code in a Jupyter Notebook the plots should show up just fine!

met927
  • 311
  • 3
  • 9
  • I understand this, I do prefer spyder over Jupyter. is there anyway to make it work on spyder? if not that is fine but i thought i should ask. – tinjinkin May 05 '20 at 01:34
  • I have never used spyder before I am afraid so I can't help any further. If when normally using matplot the plots just show up, but here they don't, then I think that may be an issue with qiskit. You can raise it as an issue here https://github.com/Qiskit/qiskit-terra/issues – met927 May 05 '20 at 09:52
0

I generally use pycharm ide for running the qiskit code. I think, spyder should also work the same. Please modify your code as below. I hope, it will work for you.

import numpy 
import qiskit as qc 
from qiskit import QuantumCircuit, execute, Aer
import matplotlib
from qiskit.visualization import plot_state_city
import matplotlib.pyplot as plt

circ = qc.QuantumCircuit(3)

circ.h(0)
circ.cx(0,1)
circ.cx(0,2)
circ.draw(output='mpl')

backend = Aer.get_backend('statevector_simulator')
job = execute(circ, backend)
result = job.result()
outputstate = result.get_statevector(circ, decimals=3)
print(outputstate)
plot_state_city(outputstate)

plt.show() 
Manu
  • 177
  • 9
0

1st: I changed the preferences of spyder: Tools ==> Preferences ==> ipython console ==> Graphics ==> Graphics backend ==> Automatic.

2nd: then I have tried the option mentioned in the answer above, with minor modification is that by writing 'mpl' only between the brackets after the word "draw" to have the code be circ.draw('mpl'), and things worked fine.