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.
Asked
Active
Viewed 437 times
1 Answers
1
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
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 = q.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()

krm
- 847
- 8
- 13