bloch_sphere(vectors=None, vectors_color=None, vectors_alpha=None, vectors_annotation=False, points=None, points_color=None, points_alpha=None, figsize=(350, 350), label_fontsize=16, annotation_fontsize=10, as_widget=False)[source]

Generates a Bloch sphere from a given collection of vector and/or points data expressed in cartesian coordinates, [x, y, z].

  • vectors (list, ndarray) – Collection of one or more vectors to display.

  • vectors_color (str or list) – List of colors to use when plotting vectors.

  • vectors_alpha (float or list) – List of alphas to use when plotting vectors.

  • vectors_annotation (bool or list) – Boolean values to determine if a annotation should be displayed.

  • points (list, ndarray) – Collection of one or more points to display.

  • points_color (str or list) – List of colors to use when plotting points.

  • points_alpha (float or list) – List of alphas to use when plotting points.

  • figsize (tuple) – Figure size in pixels.

  • label_fontsize (int) – Font size for axes labels.

  • annotation_fontsize (int) – Font size for annotations.

  • as_widget (bool) – Return plot as a widget.


A Plotly figure or widget instance

Return type

PlotlyFigure or PlotlyWidget

  • ValueError – Input lengths do not match.

  • KaleidoscopeError – Invalid vector input.


import numpy as np
from matplotlib.colors import LinearSegmentedColormap, rgb2hex
from kaleidoscope.interactive import bloch_sphere

cm = LinearSegmentedColormap.from_list('graypurple', ["#999999", "#AA00FF"])

pointsx = [[0, -np.sin(th), np.cos(th)] for th in np.linspace(0, np.pi/2, 20)]
pointsz = [[np.sin(th), -np.cos(th), 0] for th in np.linspace(0, 3*np.pi/4, 30)]

points = pointsx + pointsz

points_alpha = [np.linspace(0.8, 1, len(points))]

points_color = [[rgb2hex(cm(kk)) for kk in np.linspace(-1,1,len(points))]]

vectors_color = ["#777777", "#AA00FF"]

             vectors=[[0, 0, 1], [1/np.sqrt(2), 1/np.sqrt(2), 0]],