from qiskit import QuantumCircuit, assemble, Aer
from qiskit.visualization import plot_histogram

# create quantum circuit
qc = QuantumCircuit(1)           # 1 quantum register, 1 classical register

qc.x(0)                          # add a gate to the circuit
qc.measure_all()                 # add measurement at the end

# run
sim = Aer.get_backend('aer_simulator')
qobj = assemble(qc)              # Assemble a list of circuits or pulse schedules into a Qobj
result = sim.run(qobj).result()  # run circuit, get results

# output statistics
counts = result.get_counts()     # extract statistics from results
print(counts)

plot_histogram(counts)

qc.draw("mpl")

from qiskit.visualization import plot_bloch_vector

vector = [0, 1, 0]         # coordinates [x, y, z]
plot_bloch_vector(vector)  # plot in the Bloch sphere

qc = QuantumCircuit(1)
qc.x(0)
qc.y(0)
qc.z(0)
qc.draw("mpl")

from qiskit import QuantumCircuit, assemble, Aer
from qiskit.visualization import plot_bloch_multivector
import numpy as np

# create quantum circuit
qc = QuantumCircuit(1)

qc.x(0)                                # add gate x(qubit)

# run
sim = Aer.get_backend('aer_simulator')
qc.save_statevector()                  # we want to use statevector later
qobj = assemble(qc)
result = sim.run(qobj).result()         # run circuit, get results
final_state = result.get_statevector()  # get the final state from the result

# visualize
plot_bloch_multivector(final_state)     # display final state directly on Bloch sphere

from qiskit import QuantumCircuit, assemble, Aer
from qiskit.visualization import plot_bloch_multivector
import numpy as np

# create quantum circuit
qc = QuantumCircuit(1)
init_state = [1. / np.sqrt(2), 1. / np.sqrt(2)]  # define initial state [a,b] like a**2 + b**2 = 1 (normalization)
qc.initialize(init_state, 0)                     # initialize qubit 0 to init_state
qc.z(0)                                          # add gate z(qubit)

# run
sim = Aer.get_backend('aer_simulator')
qc.save_statevector()                   # we want to use statevector later
qobj = assemble(qc)
result = sim.run(qobj).result()         # run circuit, get results
final_state = result.get_statevector()  # get the final state from the result

# visualize
plot_bloch_multivector(final_state)     # display final state directly on Bloch sphere