def bar_response(results_list, output_path):

    output_dir = os.path.join(output_path, "charts")
    if os.path.isdir(output_dir) is False:
        os.mkdir(output_dir)

    tools = "pan,wheel_zoom,box_zoom,reset,hover,save"

    for df in results_list:
        print(df)
        p = Bar(df,
                label='hh_type',
                values='perc_res',
                stack='digital',
                title="a_title",
                legend='top_right',
                tools=tools)

        hover = p.select_one(HoverTool)
        hover.point_policy = "follow_mouse"
        hover.tooltips = [
            ("count", "@height"),
        ]
        output_file_path = os.path.join(output_dir, 'test bar.html')
        output_file(output_file_path)
        show(p)
Пример #2
0
def bar_response(results_list, output_path):

    output_dir = os.path.join(output_path, "charts")
    if os.path.isdir(output_dir) is False:
        os.mkdir(output_dir)

    tools = "pan,wheel_zoom,box_zoom,reset,hover,save"

    for df in results_list:
        print(df)
        p = Bar(df, label='hh_type', values='perc_res', stack='digital', title="a_title",
                legend='top_right', tools=tools)

        hover = p.select_one(HoverTool)
        hover.point_policy = "follow_mouse"
        hover.tooltips = [
            ("count", "@height"),
        ]
        output_file_path = os.path.join(output_dir, 'test bar.html')
        output_file(output_file_path)
        show(p)
Пример #3
0
def make_stacked_bar_chart(buckets,
                           stack,
                           data,
                           palette,
                           width=500,
                           height=500):
    cp = data
    if buckets == "day":
        cp[buckets] = cp.apply(lambda row: row['pickup_datetime'].weekday(),
                               axis=1)
    elif buckets == "month":
        cp[buckets] = cp.apply(lambda row: row['pickup_datetime'].month,
                               axis=1)
    TOOLS = "pan,reset,hover,save"
    stacked_bar = Bar(cp,
                      label=buckets,
                      values=buckets,
                      agg='count',
                      stack=cat(stack, sort=True),
                      tools=TOOLS,
                      title="{0} Stacked Bar for {1}".format(
                          ("Daily" if buckets == "day" else "Monthly"),
                          stack.replace("_", " ").title()),
                      palette=palette,
                      plot_width=width,
                      plot_height=height,
                      toolbar_location="above",
                      toolbar_sticky=False,
                      legend_sort_field='color',
                      legend_sort_direction='ascending',
                      responsive=True)
    hover = stacked_bar.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [("Frequency", "@height"),
                      ("{0}".format(stack.replace("_", " ").title()),
                       "@{0}".format(stack))]

    def day_ticker():
        days = [
            "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
            "Sunday"
        ]
        if abs(int(round(tick)) - tick) < .05:
            return days[int(round(tick))]
        else:
            return ""

    def month_ticker():
        months = [
            "January", "February", "March", "April", "May", "June", "July"
        ]
        if abs(int(round(tick)) - tick) < .05:
            return months[int(round(tick))]
        else:
            return ""

    if buckets == "day":
        stacked_bar.xaxis.formatter = FuncTickFormatter.from_py_func(
            day_ticker)
    else:
        stacked_bar.xaxis.formatter = FuncTickFormatter.from_py_func(
            month_ticker)
    stacked_bar.grid.grid_line_color = "SlateGray"
    stacked_bar.grid.grid_line_alpha = .5
    stacked_bar.grid.minor_grid_line_color = "SlateGray"
    stacked_bar.grid.minor_grid_line_alpha = .2

    return stacked_bar
Пример #4
0
def templateCoefRegression(c='c00001'):
    data = pd.read_csv(DATA + 'LogisticRegressionCoef_' + c + '_true.csv', header=0)

    data_month = data.ix[12:23, ]
    data_month = data_month.reindex([16, 15, 19, 12, 20, 18, 17, 13, 23, 22, 21, 14])

    data_empl = data.ix[0:11, ]
    data_empl = data_empl.reindex([10, 0, 2, 3, 4, 5, 6, 7, 8, 9, 1, 11])

    data_state = data.ix[24:74, ]
    data_other = data.ix[75:76, ]

    pMonth = Bar(data_month, 'coef', values='val', legend=False, tools='hover')
    pMonth.x_range = FactorRange(factors=data_month['coef'].tolist())
    pMonth.xaxis.axis_label = 'Coefficients'
    pMonth.yaxis.axis_label = 'Value'
    hover = pMonth.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Coef: ", "@coef"),
        ("Value: ", "@height")
    ]
    # show(pMonth)

    pEmpl = Bar(data_empl, 'coef', values='val', legend=False, tools='hover')
    pEmpl.x_range = FactorRange(factors=data_empl['coef'].tolist())
    pEmpl.xaxis.axis_label = 'Coefficients'
    pEmpl.yaxis.axis_label = 'Value'
    hover = pEmpl.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Coef: ", "@coef"),
        ("Value: ", "@height")

    ]
    # show(pEmpl)

    pState = Bar(data_state, 'coef', values='val', legend=False, tools='hover', width=1200)
    # # pState.x_range = FactorRange(factors=dm['coef'].tolist())
    pState.xaxis.axis_label = 'Coefficients'
    pState.yaxis.axis_label = 'Value'
    hover = pState.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Coef: ", "@coef"),
        ("Value: ", "@height")

    ]

    # show(pState)

    pOther = Bar(data_other, 'coef', values='val', legend=False, tools='hover')
    pOther.xaxis.axis_label = 'Coefficients'
    pOther.yaxis.axis_label = 'Value'
    # pOther.x_range = FactorRange(factors=data_other['coef'].tolist())
    hover = pOther.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Coef: ", "@coef"),
        ("Value: ", "@height")

    ]

    # show(pOther)

    scriptM, divM = components(pMonth)
    scriptE, divE = components(pEmpl)
    scriptS, divS = components(pState)
    scriptO, divO = components(pOther)

    dic_r = {'month': [scriptM, divM], 'empl': [scriptE, divE], 'state': [scriptS, divS], 'other': [scriptO, divO]}

    return dic_r