Esempio n. 1
0
def bloch(ex_values, tlist, ops):
    """Plots expectation values of sx, sy and sz on the Bloch sphere.
    If one of these operators is not calculated, zeros are passed for that operator.
    
    Parameters:
    -----------
    ex_values : qutip.Result.expect or list
                expectation values per operator
    tlist : list, or numpy array
            times at which expectation values are evaluated
    ops : list
          operators of which the expectation values are found in ex_values
    
    Remark:
    -------
    Does not plot a color bar yet. The lines from the QuTiP tutorial (https://nbviewer.jupyter.org/github/qutip/qutip-notebooks/blob/master/examples/bloch_sphere_with_colorbar.ipynb), commented out down here, give an error which I have not been able to solve yet.
    """
    
    if 'sx' in ops:
        sx_exp = ex_values[ops.index('sx')]
    elif 'sx' not in ops:
        sx_exp = np.zeros(len(list(tlist)))
    if 'sy' in ops:
        sy_exp = ex_values[ops.index('sy')]
    elif 'sy' not in ops:
        sy_exp = np.zeros(len(list(tlist)))
    if 'sz' in ops:
        sz_exp = ex_values[ops.index('sz')]
    elif 'sz' not in ops:
        sz_exp = np.zeros(len(list(tlist)))
    
    b = Bloch()
    b.add_points([sx_exp, sy_exp, sz_exp], 'm')
    
    nrm = Normalize(-2,10)
    colors = cm.hot(nrm(tlist))
    b.point_color = list(colors)
    b.point_marker = ['o']
    # TODO: Plot color bar
#     left, bottom, width, height = [0.98, 0.05, 0.05, 0.9]
#     ax2 = b.fig.add_axes([left, bottom, width, height])
#     ColorbarBase(ax2, cmap=cm.hot, norm=nrm, orientation='vertical')
    b.show()
Esempio n. 2
0
 def plot_point_test(self, fig, point_kws):
     b = Bloch(fig=fig)
     for kw in point_kws:
         points = kw.pop("points")
         b.add_points(points, **kw)
     b.render()