from qiskit.tools.visualization import plot_histogram

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute, BasicAer

q = QuantumRegister(2)
c = ClassicalRegister(2)

# quantum circuit to make a Bell state 
bell = QuantumCircuit(q,c)
bell.h(q[0])
bell.cx(q[0],q[1])

meas = QuantumCircuit(q,c)
meas.measure(q, c)

# execute the quantum circuit 
backend = BasicAer.get_backend('qasm_simulator') # the device to run on
circ = bell+meas
result = execute(circ, backend, shots=1000).result()
counts  = result.get_counts(circ)
print(counts)

plot_histogram(counts)

# Execute 2 qubit Bell state again
second_result = execute(circ, backend, shots=1000).result()
second_counts  = second_result.get_counts(circ)
# Plot results with legend
legend = ['First execution', 'Second execution']
plot_histogram([counts, second_counts], legend=legend)

plot_histogram([counts, second_counts], legend=legend, sort='desc', figsize=(15,12), color=['orange', 'black'], bar_labels=False)

from qiskit.tools.visualization import iplot_histogram

# Run in interactive mode
iplot_histogram(counts)

from qiskit.tools.visualization import plot_state_city, plot_bloch_multivector, plot_state_paulivec, plot_state_hinton, plot_state_qsphere

# execute the quantum circuit 
backend = BasicAer.get_backend('statevector_simulator') # the device to run on
result = execute(bell, backend).result()
psi  = result.get_statevector(bell)

plot_state_city(psi)

plot_state_hinton(psi)

plot_state_qsphere(psi)

plot_state_paulivec(psi)

plot_bloch_multivector(psi)

plot_state_city(psi, title="My City", color=['black', 'orange'])

plot_state_hinton(psi, title="My Hinton")

plot_state_paulivec(psi, title="My Paulivec", color=['purple', 'orange', 'green'])

plot_bloch_multivector(psi, title="My Bloch Spheres")

from qiskit.tools.visualization import iplot_state_paulivec

# Generate an interactive pauli vector plot
iplot_state_paulivec(psi)

from qiskit.tools.visualization import plot_bloch_vector

plot_bloch_vector([0,1,0])

plot_bloch_vector([0,1,0], title='My Bloch Sphere')

