# How to implement subplots (several blochsphere plots) using qiskit?

Qiskit seems to use matplotlib for rendering bloch spheres under the hood. Therefore, it would be nice if we could also make use of matplotlib's subplot technique.

I would like to implement subplots, each containing a bloch sphere (with different vectors), like the plot matrix in this example. I would be very grateful for a short help.

The result should look something like this at the end of the day:

• Qiskit's visualization methods like plot_bloch_vector return a matplotlib figure instance. For example: fig = plt.figure(plot_bloch_vector([0,1,0])). Did you try to plot multiple figures like this? Jun 20 at 10:27
• It sounds to be a good idea. I didn't tired that. Jun 20 at 10:37

Function plot_bloch_vector accepts matplotlib.axes.Axes to use for rendering the bloch sphere. So, you can create a figure, add a new Axes for each bloch sphere, then pass it to plot_bloch_vector:

from qiskit.visualization import plot_bloch_vector
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(figsize = [6, 9])

states = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[0.6, 0.8, 0],
[0.6, 0, 0.8],
[0, 0.6, 0.8],
]

# Values are in fractions of figure width and height:
positions = [
[0, 0],
[0.5, 0],
[0, 0.333],
[0.5, 0.333],
[0, 0.667],
[0.5, 0.667],
]

for m in range(len(states)):
ax = fig.add_axes([positions[m][0], positions[m][1], 0.5, 0.333], axes_class = Axes3D)
plot_bloch_vector(states[m], ax = ax)


The result:

• This is exactly what I was looking for. It even allows me to use the well-known axes methods from matplotlib. Thank you! Jun 20 at 19:35