def plot_bloch_vector(bloch, title="", ax=None, figsize=None): """Plot the Bloch sphere. Plot a sphere, axes, the Bloch vector, and its projections onto each axis. Args: bloch (list[double]): array of three elements where [<x>, <y>, <z>] title (str): a string that represents the plot title ax (matplotlib.Axes): An Axes to use for rendering the bloch sphere figsize (tuple): Figure size in inches. Has no effect is passing `ax`. Returns: Figure: A matplotlib figure instance if `ax = None`. Raises: ImportError: Requires matplotlib. """ if not HAS_MATPLOTLIB: raise ImportError('Must have Matplotlib installed.') if figsize is None: figsize = (5, 5) B = Bloch(axes=ax) B.add_vectors(bloch) B.render(title=title) if ax is None: fig = B.fig fig.set_size_inches(figsize[0], figsize[1]) plt.close(fig) return fig return None
def plot_bloch_vector(bloch, title="", ax=None): """Plot the Bloch sphere. Plot a sphere, axes, the Bloch vector, and its projections onto each axis. Args: bloch (list[double]): array of three elements where [<x>, <y>,<z>] title (str): a string that represents the plot title ax (matplotlib.Axes): An Axes to use for rendering the bloch sphere """ B = Bloch(axes=ax) B.add_vectors(bloch) B.render(title=title)
def plot_bloch_vector(bloch, title="", filename=None): """Plot the Bloch sphere. Plot a sphere, axes, the Bloch vector, and its projections onto each axis. Args: bloch (list[double]): array of three elements where [<x>, <y>,<z>] title (str): a string that represents the plot title filename (str): the output file to save the plot as. If specified it will save and exit and not open up the plot in a new window. """ B = Bloch() B.add_vectors(bloch) if filename: B.save(filename) else: B.show(title=title)