예제 #1
0
def test_two():
    """Second charting test."""
    expect = {
        'layout': {'xaxis': {'title': 'x axis'}, 'yaxis': {'title': 'y label'}},
        'data': [
            {
                'y': np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
                'x': np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
                'line': {'color': 'red', 'width': 5, 'dash': 'dashdot'},
                'marker': dict(size=6),
                'type': 'scatter',
                'text': "",
                'yaxis': 'y',
                'mode': 'lines+markers',
                'name': 'hello',
            }
        ],
    }

    x = np.arange(10)

    line0 = pw.line(y=x, label='hello', color='red', dash='dashdot', width=5)
    line0.xlabel = 'x axis'
    line0.ylabel = 'y label'
    line0.show(auto_open=False)

    line1 = pw.line(x, label='hello', color='red', dash='dashdot', width=5)
    line1.xlabel = 'x axis'
    line1.ylabel = 'y label'
    line1.show(auto_open=False)

    compare_figs(line0.dict, line1.dict)
    compare_figs(line0.dict, expect)
예제 #2
0
def upgraph():
    data = cache.load('data')
    value = float(sigma.get())
    data.pop(0)
    data.append(value * rng.randn() + data[-1])
    mainplot.do_all(pw.line(data).to_json())
    cache.save('data', data)
예제 #3
0
def mainregress(selection, alpha):
    if len(selection) < 2:
        return

    x = xdown.get()['value']
    y = ydown.get()['value']

    tabdata = []
    mldatax = []
    mldatay = []
    species = iris.Species.unique()
    for i, p in enumerate(selection['points']):
        mldatax.append(p['x'])
        mldatay.append(p['y'])
        tabdata.append({
            x: p['x'],
            y: p['y'],
            'species': species[p['curve']]
        })


    X = np.c_[mldatax, np.array(mldatax) ** 2]
    ridge = KernelRidge(alpha=alpha).fit(X, mldatay)

    xspace = np.linspace(min(mldatax)-1, max(mldatax)+1, 100)

    plot = pw.scatter(mldatax, mldatay, label='train', markersize=15)
    for i, df in iris.groupby('Species'):
        plot += pw.scatter(df[x], df[y], label=i)
    plot += pw.line(xspace, ridge.predict(np.c_[xspace, xspace**2]), label='model', mode='lines')
    plot.xlabel = x
    plot.ylabel = y
    linear.do_all(plot.dict)
    table1.do_data(pd.DataFrame(tabdata))
예제 #4
0
def upgraph():
    data = cache.load('data')
    value = float(sigma.get())
    data.pop(0)
    data.append(value * rng.randn() + data[-1])
    mainplot.do_all(pw.line(data).to_json())
    cache.save('data', data)
예제 #5
0
def test_two():
    """Second charting test."""
    expect = {
        'layout': {
            'xaxis': {
                'title': 'x axis'
            },
            'yaxis': {
                'title': 'y label'
            }
        },
        'data': [{
            'y': np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
            'x': np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
            'line': {
                'color': 'red',
                'width': 5,
                'dash': 'dashdot'
            },
            'marker': dict(size=6),
            'type': 'scatter',
            'text': "",
            'yaxis': 'y',
            'mode': 'lines+markers',
            'name': 'hello',
        }],
    }

    x = np.arange(10)

    line0 = pw.line(y=x, label='hello', color='red', dash='dashdot', width=5)
    line0.xlabel = 'x axis'
    line0.ylabel = 'y label'
    line0.show(auto_open=False)

    line1 = pw.line(x, label='hello', color='red', dash='dashdot', width=5)
    line1.xlabel = 'x axis'
    line1.ylabel = 'y label'
    line1.show(auto_open=False)

    compare_figs(line0.dict, line1.dict)
    compare_figs(line0.dict, expect)
예제 #6
0
def test_dataframe_lines():
    """Test dataframe lines chart."""
    columns = list('abc')
    x = np.arange(10)
    y = rng.randn(10, 3)
    df = pd.DataFrame(y, x, columns)

    p1 = df.plotly.line()
    p1.show(auto_open=False)

    p2 = pw.line(x, y, columns)
    p2.show(auto_open=False)

    compare_figs(p1.dict, p2.dict)
예제 #7
0
def test_dataframe_lines():
    """Test dataframe lines chart."""
    columns = list('abc')
    x = np.arange(10)
    y = rng.randn(10, 3)
    df = pd.DataFrame(y, x, columns)

    p1 = df.plotly.line()
    p1.show(auto_open=False)

    p2 = pw.line(x, y, columns)
    p2.show(auto_open=False)

    compare_figs(p1.dict, p2.dict)
예제 #8
0
def test_dict():
    """Test dict accessor works."""
    js = pw.line(range(3)).dict
    expected = {
        'layout': {},
        'data': [{
            'mode': 'lines+markers',
            'marker': dict(size=6),
            'text': "",
            'y': [0, 1, 2],
            'x': [0, 1, 2],
            'yaxis': 'y',
            'type': 'scatter',
        }],
    }
    compare_figs(js, expected)
예제 #9
0
def test_dict():
    """Test dict accessor works."""
    js = pw.line(range(3)).dict
    expected = {
        'layout': {},
        'data': [
            {
                'mode': 'lines+markers',
                'marker': dict(size=6),
                'text': "",
                'y': [0, 1, 2],
                'x': [0, 1, 2],
                'yaxis': 'y',
                'type': 'scatter',
            }
        ],
    }
    compare_figs(js, expected)
예제 #10
0
def test_one():
    """First charting test."""
    x = np.arange(3)

    bars = pw.bar(x=x, y=[20, 14, 23], label='new york')
    bars2 = pw.bar(x=x, y=[12, 18, 29])  # , label='la')
    line = pw.line(x=x, y=[3, 8, 9], label='hello', color='red', dash='dashdot', width=5)
    plot = bars + bars2 + line
    # print(bars.data)
    plot.xlabel = 'x axis'
    plot.ylabel = 'y label'
    plot.stack()
    plot.show(auto_open=False)

    expect = {
        'layout': {'barmode': 'stack', 'xaxis': {'title': 'x axis'}, 'yaxis': {'title': 'y label'}},
        'data': [
            {
                'y': np.array([20, 14, 23]),
                'x': np.array([0, 1, 2]),
                'type': 'bar',
                'yaxis': 'y',
                'name': 'new york',
            },
            {'y': np.array([12, 18, 29]), 'x': np.array([0, 1, 2]), 'type': 'bar', 'yaxis': 'y'},
            {
                'y': np.array([3, 8, 9]),
                'x': np.array([0, 1, 2]),
                'line': {'color': 'red', 'width': 5, 'dash': 'dashdot'},
                'type': 'scatter',
                'marker': dict(size=6),
                'yaxis': 'y',
                'text': "",
                'mode': 'lines+markers',
                'name': 'hello',
            },
        ],
    }

    compare_figs(plot.dict, expect)
예제 #11
0
def mainregress(selection, alpha):
    if len(selection) < 2:
        return

    x = xdown.get()['value']
    y = ydown.get()['value']

    tabdata = []
    mldatax = []
    mldatay = []
    species = iris.Species.unique()
    for i, p in enumerate(selection['points']):
        mldatax.append(p['x'])
        mldatay.append(p['y'])
        tabdata.append({
            x: p['x'],
            y: p['y'],
            'species': species[p['curveNumber']]
        })

    X = np.c_[mldatax, np.array(mldatax)**2]
    ridge = KernelRidge(alpha=alpha).fit(X, mldatay)

    xspace = np.linspace(min(mldatax) - 1, max(mldatax) + 1, 100)

    plot = pw.scatter(mldatax, mldatay, label='train', markersize=15)
    for i, df in iris.groupby('Species'):
        plot += pw.scatter(df[x], df[y], label=i)
    plot += pw.line(xspace,
                    ridge.predict(np.c_[xspace, xspace**2]),
                    label='model',
                    mode='lines')
    plot.xlabel(x)
    plot.ylabel(y)
    linear.do_all(plot.to_json())
    table1.do_update(tabdata)
예제 #12
0
def listener(freq):
    freq = float(freq[0])
    t = np.linspace(0, 10, 100)
    sine_plot.do_all(pw.line(t, np.sin(freq * t)).to_json())
예제 #13
0
def walk():
    value = float(sigma.get())
    data.pop(0)
    data.append(value * rng.randn() + data[-1])
    mainplot.do_all(pw.line(data).to_json())
예제 #14
0
def twin_axes():
    chart = pw.bar(range(20, 15, -1))
    chart += pw.line(range(5), yaxis=2)
    chart.yaxis_right(2)
    chart.save('fig_twinx.html', **options)
예제 #15
0
def test_no_args():
    """Test no args raises an error."""
    with pytest.raises(AssertionError):
        pw.line()
    with pytest.raises(AssertionError):
        pw.bar()
예제 #16
0
def line():
    pw.line(data).save('fig_line.html', **options)
예제 #17
0
def line():
    pw.line(data).save('fig_line.html', **options)
예제 #18
0
def test_one():
    """First charting test."""
    x = np.arange(3)

    bars = pw.bar(x=x, y=[20, 14, 23], label='new york')
    bars2 = pw.bar(x=x, y=[12, 18, 29])  # , label='la')
    line = pw.line(x=x,
                   y=[3, 8, 9],
                   label='hello',
                   color='red',
                   dash='dashdot',
                   width=5)
    plot = bars + bars2 + line
    # print(bars.data)
    plot.xlabel = 'x axis'
    plot.ylabel = 'y label'
    plot.stack()
    plot.show(auto_open=False)

    expect = {
        'layout': {
            'barmode': 'stack',
            'xaxis': {
                'title': 'x axis'
            },
            'yaxis': {
                'title': 'y label'
            }
        },
        'data': [
            {
                'y': np.array([20, 14, 23]),
                'x': np.array([0, 1, 2]),
                'type': 'bar',
                'yaxis': 'y',
                'name': 'new york',
            },
            {
                'y': np.array([12, 18, 29]),
                'x': np.array([0, 1, 2]),
                'type': 'bar',
                'yaxis': 'y'
            },
            {
                'y': np.array([3, 8, 9]),
                'x': np.array([0, 1, 2]),
                'line': {
                    'color': 'red',
                    'width': 5,
                    'dash': 'dashdot'
                },
                'type': 'scatter',
                'marker': dict(size=6),
                'yaxis': 'y',
                'text': "",
                'mode': 'lines+markers',
                'name': 'hello',
            },
        ],
    }

    compare_figs(plot.dict, expect)
예제 #19
0
def twin_axes():
    chart = pw.bar(range(20, 15, -1))
    chart += pw.line(range(5), yaxis=2)
    chart.yaxis_right(2)
    chart.save('fig_twinx.html', **options)
예제 #20
0
def test_no_args():
    """Test no args raises an error."""
    with pytest.raises(AssertionError):
        pw.line()
    with pytest.raises(AssertionError):
        pw.bar()