Subplots with QuTip Bloch sphere

638 views Asked by At

I would like to know if is it possible to plot a figure with two subplots, in which one is a regular 2D plot and the other one a Bloch sphere.

1

There are 1 answers

3
krm On

Yes, it is possible.

You need to manually create the figure object and add axes to it using matplotlib's OO interface. While making the axes that needs to have the Bloch sphere, you should set the projection to 3D. Finally, just call the render method on your Bloch sphere object so that the Bloch sphere gets rendered to the correct subplot

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from qutip import Bloch

fig = plt.figure(constrained_layout=True)

ax1 = fig.add_subplot(1, 2, 1)
ax1.plot(range(10), range(10), "o-")

ax2 = fig.add_subplot(1, 2, 2, projection='3d')
b1 = Bloch(fig=fig, axes=ax2)
b1.render(fig=fig, axes=ax2)
ax2.set_box_aspect([1, 1, 1]) # required for mpl > 3.1

plt.show()

enter image description here