Ejemplo n.º 1
0
def btn_update__click(dom):
    symbol = dom['select_stock']['value']
    if symbol == 'AAPL':
        df = AAPL
    elif symbol == 'GOOG':
        df = GOOG
    else:
        return dom
    bounds = [dom[x]['value'] if dom[x]['value'] else None
              for x in ['date_start', 'date_end']]
    ts = df['Close'][bounds[0]:bounds[1]]
    if ts.any():
        try:
            ts.plot()
            for win in [int(dom[x]['value'])
                        for x in ['slider_window_1', 'slider_window_2']]:
                pd.rolling_mean(ts, win).plot()
            plt.title("Weekly closing prices for {}".format(symbol))

            # get_svg is added by ashiba.plot
            dom['img_plot'].set_image(plt.get_svg(), 'svg')
        finally:
            plt.close()

    return dom
Ejemplo n.º 2
0
def _plot_control__change(dom):
    year = int(dom['slider_year']['value'])
    sex = None
    if dom['radio_male']['checked']:
        sex = 1
    elif dom['radio_female']['checked']:
        sex = 2
    if year == 1890 or sex is None:
        return

    subset = df[df.year == year][df.sex == sex][df.age >= 15]
    # Does this need to be a new instantiation?
    dom['my_table'] = ashiba.dom.DataTable(data=subset)
    pivot = subset.pivot('age', 'marst', 'people')
    if 3 not in pivot:
        pivot[3] = [0] * len(pivot)
    pivot.plot(kind='bar', stacked=True, sort_columns=True)
    gender = {1: 'male', 2: 'female'}[sex]
    plt.title('Marriage records for year {}, {}'.format(year, gender))
    statuses = (
        'Unknown',
        'Married',
        'Married, Spouse Absent',
        'Separated',
        'Divorced',
        'Widowed',
        'Single',
    )
    plt.legend(statuses)
    dom['img_plot'].set_image(plt.get_svg(), 'svg')
    plt.close()
Ejemplo n.º 3
0
def btn_update__click(dom):
    symbol = dom['select_stock']['value']
    if symbol == 'AAPL':
        df = AAPL
    elif symbol == 'GOOG':
        df = GOOG
    else:
        return dom
    bounds = [
        dom[x]['value'] if dom[x]['value'] else None
        for x in ['date_start', 'date_end']
    ]
    ts = df['Close'][bounds[0]:bounds[1]]
    if ts.any():
        try:
            ts.plot()
            for win in [
                    int(dom[x]['value'])
                    for x in ['slider_window_1', 'slider_window_2']
            ]:
                pd.rolling_mean(ts, win).plot()
            plt.title("Weekly closing prices for {}".format(symbol))

            # get_svg is added by ashiba.plot
            dom['img_plot'].set_image(plt.get_svg(), 'svg')
        finally:
            plt.close()

    return dom
Ejemplo n.º 4
0
def mybutton__click(dom):

    user = dom['usersearch']['value']
    repo = dom['reposearch']['value']

    ts = weekly_commit_timeline(user, repo)
    ts2 = daily_commit_timeline(user, repo)

    ts.plot()
    plt.title("Weekly commits for %s".format('Github') % repo)
    dom['img_plot'].set_image(plt.get_svg(), 'svg')

    ts2.plot()
    plt.title("Daily commits for %s".format('Github') % repo)
    dom['img_plot2'].set_image(plt.get_svg(), 'svg')

    plt.close()

    return dom
Ejemplo n.º 5
0
def mybutton__click(dom):

    user = dom['usersearch']['value']
    repo = dom['reposearch']['value']

    ts = weekly_commit_timeline(user, repo)
    ts2 = daily_commit_timeline(user, repo)

    ts.plot()
    plt.title("Weekly commits for %s".format('Github') %repo)
    dom['img_plot'].set_image(plt.get_svg(), 'svg')

    ts2.plot()
    plt.title("Daily commits for %s".format('Github') % repo)
    dom['img_plot2'].set_image(plt.get_svg(), 'svg')


    plt.close()
 
    return dom
Ejemplo n.º 6
0
def _plot_control__change(dom):
    year = int(dom["slider_year"]["value"])
    sex = None
    if dom["radio_male"]["checked"]:
        sex = 1
    elif dom["radio_female"]["checked"]:
        sex = 2
    if year == 1890 or sex is None:
        return

    subset = df[df.year == year][df.sex == sex][df.age >= 15]
    # Does this need to be a new instantiation?
    dom["my_table"] = ashiba.dom.DataTable(data=subset)
    pivot = subset.pivot("age", "marst", "people")
    if 3 not in pivot:
        pivot[3] = [0] * len(pivot)
    pivot.plot(kind="bar", stacked=True, sort_columns=True)
    gender = {1: "male", 2: "female"}[sex]
    plt.title("Marriage records for year {}, {}".format(year, gender))
    statuses = ("Unknown", "Married", "Married, Spouse Absent", "Separated", "Divorced", "Widowed", "Single")
    plt.legend(statuses)
    dom["img_plot"].set_image(plt.get_svg(), "svg")
    plt.close()