Example #1
0
def distribution():

    mu, sigma = 0, 0.5

    measured = np.random.normal(mu, sigma, 1000)
    hist, edges = np.histogram(measured, density=True, bins=20)

    x = np.linspace(-2, 2, 1000)
    pdf = 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(x - mu) ** 2 / (2 * sigma ** 2))
    cdf = (1 + scipy.special.erf((x - mu) / np.sqrt(2 * sigma ** 2))) / 2

    output_server("distribution_reveal")

    hold()

    figure(title="Interactive plots",
           tools="pan, wheel_zoom, box_zoom, reset, previewsave",
           background_fill="#E5E5E5")
    quad(top=hist, bottom=np.zeros(len(hist)), left=edges[:-1], right=edges[1:],
         fill_color="#333333", line_color="#E5E5E5", line_width=3)

    # Use `line` renderers to display the PDF and CDF
    line(x, pdf, line_color="#348abd", line_width=8, alpha=0.7, legend="PDF")
    line(x, cdf, line_color="#7a68a6", line_width=8, alpha=0.7, legend="CDF")

    xgrid().grid_line_color = "white"
    xgrid().grid_line_width = 3
    ygrid().grid_line_color = "white"
    ygrid().grid_line_width = 3

    legend().orientation = "top_left"

    return curplot(), cursession()
Example #2
0
def posture_signals(kin_env,
                    m_signals,
                    title='posture graphs',
                    color='#666666',
                    alpha=1.0,
                    radius_factor=1.0,
                    swap_xy=True,
                    x_range=[-1.0, 1.0],
                    y_range=[-1.0, 1.0],
                    **kwargs):

    for m_signal in m_signals:
        m_vector = kin_env.flatten_synergies(m_signal)
        s_signal = kin_env._multiarm.forward_kin(m_vector)

        xs, ys = [0.0], [0.0]
        for i in range(kin_env.cfg.dim):
            xs.append(s_signal['x{}'.format(i + 1)])
            ys.append(s_signal['y{}'.format(i + 1)])

        if isinstance(kin_env.cfg.lengths, numbers.Real):
            total_length = kin_env.cfg.lengths * kin_env.cfg.dim
        else:
            total_length = sum(kin_env.cfg.lengths)
        total_length += 0.0

        kwargs.update({
            'x_range': x_range,
            'y_range': y_range,
            'line_color': color,
            'line_alpha': alpha,
            'fill_color': color,
            'fill_alpha': alpha,
            'title': title
        })

        if swap_xy:
            xs, ys = ys, xs

        plotting.line(xs, ys, line_width=2.0 * radius_factor, **kwargs)
        plotting.hold(True)
        plotting.grid().grid_line_color = None
        plotting.ygrid().grid_line_color = None
        plotting_axis()

        plotting.circle(xs[:1], ys[:1], radius=radius_factor * 0.015, **kwargs)
        plotting.circle(xs[1:-1],
                        ys[1:-1],
                        radius=radius_factor * 0.008,
                        **kwargs)
        plotting.circle(xs[-1:],
                        ys[-1:],
                        radius=radius_factor * 0.01,
                        color='red',
                        alpha=alpha)
    plotting.hold(False)
Example #3
0
def posture_signals(
    kin_env,
    m_signals,
    title="posture graphs",
    color="#666666",
    alpha=1.0,
    radius_factor=1.0,
    swap_xy=True,
    x_range=[-1.0, 1.0],
    y_range=[-1.0, 1.0],
    **kwargs
):

    for m_signal in m_signals:
        m_vector = kin_env.flatten_synergies(m_signal)
        s_signal = kin_env._multiarm.forward_kin(m_vector)

        xs, ys = [0.0], [0.0]
        for i in range(kin_env.cfg.dim):
            xs.append(s_signal["x{}".format(i + 1)])
            ys.append(s_signal["y{}".format(i + 1)])

        if isinstance(kin_env.cfg.lengths, numbers.Real):
            total_length = kin_env.cfg.lengths * kin_env.cfg.dim
        else:
            total_length = sum(kin_env.cfg.lengths)
        total_length += 0.0

        kwargs.update(
            {
                "x_range": x_range,
                "y_range": y_range,
                "line_color": color,
                "line_alpha": alpha,
                "fill_color": color,
                "fill_alpha": alpha,
                "title": title,
            }
        )

        if swap_xy:
            xs, ys = ys, xs

        plotting.line(xs, ys, line_width=2.0 * radius_factor, **kwargs)
        plotting.hold(True)
        plotting.grid().grid_line_color = None
        plotting.ygrid().grid_line_color = None
        plotting_axis()

        plotting.circle(xs[:1], ys[:1], radius=radius_factor * 0.015, **kwargs)
        plotting.circle(xs[1:-1], ys[1:-1], radius=radius_factor * 0.008, **kwargs)
        plotting.circle(xs[-1:], ys[-1:], radius=radius_factor * 0.01, color="red", alpha=alpha)
    plotting.hold(False)
Example #4
0
def distribution():

    mu, sigma = 0, 0.5

    measured = np.random.normal(mu, sigma, 1000)
    hist, edges = np.histogram(measured, density=True, bins=20)

    x = np.linspace(-2, 2, 1000)
    pdf = 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(x - mu)**2 /
                                                    (2 * sigma**2))
    cdf = (1 + scipy.special.erf((x - mu) / np.sqrt(2 * sigma**2))) / 2

    output_server("distribution_reveal")

    hold()

    figure(title="Interactive plots",
           tools="pan, wheel_zoom, box_zoom, reset, previewsave",
           background_fill="#E5E5E5")
    quad(top=hist,
         bottom=np.zeros(len(hist)),
         left=edges[:-1],
         right=edges[1:],
         fill_color="#333333",
         line_color="#E5E5E5",
         line_width=3)

    # Use `line` renderers to display the PDF and CDF
    line(x, pdf, line_color="#348abd", line_width=8, alpha=0.7, legend="PDF")
    line(x, cdf, line_color="#7a68a6", line_width=8, alpha=0.7, legend="CDF")

    xgrid().grid_line_color = "white"
    xgrid().grid_line_width = 3
    ygrid().grid_line_color = "white"
    ygrid().grid_line_width = 3

    legend().orientation = "top_left"

    return curplot(), cursession()
Example #5
0
def bokeh_kin(kin_env, m_signal, color='#DF4949', alpha=1.0, **kwargs):

    m_vector = tools.to_vector(m_signal, kin_env.m_channels)
    s_signal = kin_env._multiarm.forward_kin(m_vector)

    xs, ys = [0.0], [0.0]
    for i in range(kin_env.cfg.dim):
        xs.append(s_signal['x{}'.format(i + 1)])
        ys.append(s_signal['y{}'.format(i + 1)])
    xs, ys = ys, xs  # we swap x and y for a more symmetrical look

    if isinstance(kin_env.cfg.lengths, numbers.Real):
        total_length = kin_env.cfg.lengths * kin_env.cfg.dim
    else:
        total_length = sum(kin_env.cfg.lengths)
    total_length += 0.0

    kwargs = {
        'plot_height': int(350 * 1.60),
        'plot_width': int(350 * 1.60),
        'x_range': [-1.0, 1.0],
        'y_range': [-1.0, 1.0],
        'line_color': color,
        'line_alpha': alpha,
        'fill_color': color,
        'fill_alpha': alpha,
        'title': ''
    }

    plotting.hold()
    plotting.line(xs, ys, **kwargs)
    plotting.grid().grid_line_color = None
    plotting.xaxis().major_tick_in = 0
    plotting.ygrid().grid_line_color = None
    plotting.yaxis().major_tick_in = 0

    plotting.circle(xs[:1], ys[:1], radius=0.015, **kwargs)
    plotting.circle(xs[1:-1], ys[1:-1], radius=0.008, **kwargs)
    plotting.circle(xs[-1:], ys[-1:], radius=0.01, color='red')
    plotting.hold(False)
Example #6
0
def bokeh_kin(kin_env, m_signal, color='#DF4949', alpha=1.0, **kwargs):

    m_vector = tools.to_vector(m_signal, kin_env.m_channels)
    s_signal = kin_env._multiarm.forward_kin(m_vector)

    xs, ys = [0.0], [0.0]
    for i in range(kin_env.cfg.dim):
        xs.append(s_signal['x{}'.format(i+1)])
        ys.append(s_signal['y{}'.format(i+1)])
    xs, ys = ys, xs # we swap x and y for a more symmetrical look

    if isinstance(kin_env.cfg.lengths, numbers.Real):
        total_length = kin_env.cfg.lengths*kin_env.cfg.dim
    else:
        total_length = sum(kin_env.cfg.lengths)
    total_length += 0.0

    kwargs ={'plot_height' : int(350*1.60),
             'plot_width'  : int(350*1.60),
             'x_range'     : [-1.0, 1.0],
             'y_range'     : [-1.0, 1.0],
             'line_color'  : color,
             'line_alpha'  : alpha,
             'fill_color'  : color,
             'fill_alpha'  : alpha,
             'title':''
            }

    plotting.hold()
    plotting.line(xs, ys, **kwargs)
    plotting.grid().grid_line_color = None
    plotting.xaxis().major_tick_in   = 0
    plotting.ygrid().grid_line_color = None
    plotting.yaxis().major_tick_in   = 0

    plotting.circle(xs[  : 1], ys[  : 1], radius=0.015, **kwargs)
    plotting.circle(xs[ 1:-1], ys[ 1:-1], radius=0.008, **kwargs)
    plotting.circle(xs[-1:  ], ys[-1:  ], radius=0.01, color='red')
    plotting.hold(False)
Example #7
0
 def test_ygrid(self):
     plt.figure()
     p = plt.circle([1,2,3], [1,2,3])
     self.assertEqual(len(plt.ygrid()), 1)
     self.assertEqual(plt.ygrid()[0].dimension, 1)
Example #8
0
 def test_ygrid(self):
     plt.figure()
     p = plt.circle([1,2,3], [1,2,3])
     self.assertEqual(len(plt.ygrid()), 1)
     self.assertEqual(plt.ygrid()[0].dimension, 1)