neuroprob/utils/plot.py
def plot_circ_posterior(ax, times, wrap_y, y_std, col='k', linewidth=1., step=1, alpha=0.5, line_alpha=1., 
                        l=None, l_std=None):
    """
    Plot circular variables with (approximate) variational uncertainty.
    """
    if y_std is not None:
        upper = wrap_y + y_std
        lower = wrap_y - y_std

    T = len(wrap_y)
    for i in np.arange(T)[1::step]:
        lines = []
        delta = wrap_y[i] - wrap_y[i-1]
        if delta > np.pi:
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1], wrap_y[i]-2*np.pi], 
                        color=col, linewidth=linewidth, label=l, alpha=line_alpha)[0])
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1]+2*np.pi, wrap_y[i]], 
                        color=col, linewidth=linewidth, label=None, alpha=line_alpha)[0])
        elif delta < -np.pi:
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1], wrap_y[i]+2*np.pi], 
                        color=col, linewidth=linewidth, label=l, alpha=line_alpha)[0])
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1]-2*np.pi, wrap_y[i]], 
                        color=col, linewidth=linewidth, label=None, alpha=line_alpha)[0])
        else:
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1], wrap_y[i]], 
                         color=col, linewidth=linewidth, label=l, alpha=line_alpha)[0])
            if y_std is not None: # double locations for uncertainty
                if upper[i] > 2*np.pi or upper[i-1] > 2*np.pi:
                    lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1]-2*np.pi, wrap_y[i]-2*np.pi], 
                                 color=col, linewidth=linewidth, label=None, alpha=line_alpha)[0])
                elif lower[i] < 0 or lower[i-1] < 0:
                    lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1]+2*np.pi, wrap_y[i]+2*np.pi], 
                                 color=col, linewidth=linewidth, label=None, alpha=line_alpha)[0])
            
        if y_std is not None:
            for line in lines:
                ax.fill_between(
                    [times[i-1], times[i]], line.get_ydata() - y_std[i-1:i+1],
                    line.get_ydata() + y_std[i-1:i+1], color=line.get_color(), alpha=alpha, label=l_std
                )
                l_std = None
                
        l = None

    Plot circular variables with (approximate) variational uncertainty.
    
Plot circular variables with (approximate) variational uncertainty.
Plot circular variables with ( approximate ) variational uncertainty .
def plot_circ_posterior(ax, times, wrap_y, y_std, col='k', linewidth=1., step=1, alpha=0.5, line_alpha=1., 
                        l=None, l_std=None):
    if y_std is not None:
        upper = wrap_y + y_std
        lower = wrap_y - y_std
    T = len(wrap_y)
    for i in np.arange(T)[1::step]:
        lines = []
        delta = wrap_y[i] - wrap_y[i-1]
        if delta > np.pi:
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1], wrap_y[i]-2*np.pi], 
                        color=col, linewidth=linewidth, label=l, alpha=line_alpha)[0])
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1]+2*np.pi, wrap_y[i]], 
                        color=col, linewidth=linewidth, label=None, alpha=line_alpha)[0])
        elif delta < -np.pi:
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1], wrap_y[i]+2*np.pi], 
                        color=col, linewidth=linewidth, label=l, alpha=line_alpha)[0])
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1]-2*np.pi, wrap_y[i]], 
                        color=col, linewidth=linewidth, label=None, alpha=line_alpha)[0])
        else:
            lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1], wrap_y[i]], 
                         color=col, linewidth=linewidth, label=l, alpha=line_alpha)[0])
            if y_std is not None: 
                if upper[i] > 2*np.pi or upper[i-1] > 2*np.pi:
                    lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1]-2*np.pi, wrap_y[i]-2*np.pi], 
                                 color=col, linewidth=linewidth, label=None, alpha=line_alpha)[0])
                elif lower[i] < 0 or lower[i-1] < 0:
                    lines.append(ax.plot([times[i-1], times[i]], [wrap_y[i-1]+2*np.pi, wrap_y[i]+2*np.pi], 
                                 color=col, linewidth=linewidth, label=None, alpha=line_alpha)[0])
        if y_std is not None:
            for line in lines:
                ax.fill_between(
                    [times[i-1], times[i]], line.get_ydata() - y_std[i-1:i+1],
                    line.get_ydata() + y_std[i-1:i+1], color=line.get_color(), alpha=alpha, label=l_std
                )
                l_std = None
        l = None
def plot_circ_posterior ( ax , times , wrap_y , y_std , col = 'k' , linewidth = 1. , step = 1 , alpha = 0.5 , line_alpha = 1. , l = None , l_std = None ) : if y_std is not None : upper = wrap_y + y_std lower = wrap_y - y_std T = len ( wrap_y ) for i in np . arange ( T ) [ 1 : : step ] : lines = [ ] delta = wrap_y [ i ] - wrap_y [ i - 1 ] if delta > np . pi : lines . append ( ax . plot ( [ times [ i - 1 ] , times [ i ] ] , [ wrap_y [ i - 1 ] , wrap_y [ i ] - 2 * np . pi ] , color = col , linewidth = linewidth , label = l , alpha = line_alpha ) [ 0 ] ) lines . append ( ax . plot ( [ times [ i - 1 ] , times [ i ] ] , [ wrap_y [ i - 1 ] + 2 * np . pi , wrap_y [ i ] ] , color = col , linewidth = linewidth , label = None , alpha = line_alpha ) [ 0 ] ) elif delta < - np . pi : lines . append ( ax . plot ( [ times [ i - 1 ] , times [ i ] ] , [ wrap_y [ i - 1 ] , wrap_y [ i ] + 2 * np . pi ] , color = col , linewidth = linewidth , label = l , alpha = line_alpha ) [ 0 ] ) lines . append ( ax . plot ( [ times [ i - 1 ] , times [ i ] ] , [ wrap_y [ i - 1 ] - 2 * np . pi , wrap_y [ i ] ] , color = col , linewidth = linewidth , label = None , alpha = line_alpha ) [ 0 ] ) else : lines . append ( ax . plot ( [ times [ i - 1 ] , times [ i ] ] , [ wrap_y [ i - 1 ] , wrap_y [ i ] ] , color = col , linewidth = linewidth , label = l , alpha = line_alpha ) [ 0 ] ) if y_std is not None : if upper [ i ] > 2 * np . pi or upper [ i - 1 ] > 2 * np . pi : lines . append ( ax . plot ( [ times [ i - 1 ] , times [ i ] ] , [ wrap_y [ i - 1 ] - 2 * np . pi , wrap_y [ i ] - 2 * np . pi ] , color = col , linewidth = linewidth , label = None , alpha = line_alpha ) [ 0 ] ) elif lower [ i ] < 0 or lower [ i - 1 ] < 0 : lines . append ( ax . plot ( [ times [ i - 1 ] , times [ i ] ] , [ wrap_y [ i - 1 ] + 2 * np . pi , wrap_y [ i ] + 2 * np . pi ] , color = col , linewidth = linewidth , label = None , alpha = line_alpha ) [ 0 ] ) if y_std is not None : for line in lines : ax . fill_between ( [ times [ i - 1 ] , times [ i ] ] , line . get_ydata ( ) - y_std [ i - 1 : i + 1 ] , line . get_ydata ( ) + y_std [ i - 1 : i + 1 ] , color = line . get_color ( ) , alpha = alpha , label = l_std ) l_std = None l = None
Plot circular variables with (approximate) variational uncertainty.
Plot circular variables with ( approximate ) variational uncertainty .
"""
    Plot circular variables with (approximate) variational uncertainty.
    """ # double locations for uncertainty
ax
times
wrap_y
y_std
col
linewidth
step
alpha
line_alpha
l
l_std