def set_graph_and_legend_properties(plot_graph, legends, scenario):
    # Add Tool - Hovertool
    # Hover Tool Properties
    hover_tool_tips = set_hover_tool_tips()
    plot_graph.add_tools(hover_tool_tips)

    # Legend related formatting
    legend = Legend(items=legends, location=(0, 0))
    legend.click_policy = "hide"
    legend.background_fill_color = "#2F2F2F"
    legend.label_text_color = "white"
    legend.border_line_color = "#2F2F2F"
    legend.inactive_fill_color = "#2F2F2F"
    plot_graph.add_layout(legend, 'right')

    # X-Axis related formatting
    plot_graph.xgrid.grid_line_color = "white"
    plot_graph.xgrid.grid_line_dash = [6, 4]
    plot_graph.xgrid.grid_line_alpha = .3
    plot_graph.xaxis.axis_line_color = "white"
    plot_graph.xaxis.axis_label_text_color = "white"
    plot_graph.xaxis.major_label_text_color = "white"
    plot_graph.xaxis.major_tick_line_color = "white"
    plot_graph.xaxis.minor_tick_line_color = "white"
    plot_graph.xaxis.formatter = DatetimeTickFormatter(
        microseconds=["%H:%M:%S"],
        milliseconds=["%H:%M:%S"],
        seconds=["%H:%M:%S"],
        minsec=["%H:%M:%S"],
        minutes=["%H:%M"],
        hourmin=["%H:%M"],
        hours=["%H:%M"],
        days=["%H:%M"],
        months=["%H:%M"],
        years=["%H:%M"],
    )

    # Y-axis related formatting
    plot_graph.ygrid.grid_line_color = "white"
    plot_graph.ygrid.grid_line_dash = [6, 4]
    plot_graph.ygrid.grid_line_alpha = .3
    plot_graph.yaxis.axis_line_color = "white"
    plot_graph.yaxis.axis_label_text_color = "white"
    plot_graph.yaxis.major_label_text_color = "white"
    plot_graph.yaxis.major_tick_line_color = "white"
    plot_graph.yaxis.minor_tick_line_color = "white"

    # Graph related Formatting
    plot_graph.min_border_left = 80
    plot_graph.title.text = scenario
    plot_graph.title.text_color = "white"
    plot_graph.title.text_font = "times"
    plot_graph.title.text_font_style = "normal"
    plot_graph.title.text_font_size = "14pt"
    plot_graph.title.align = "center"
    plot_graph.background_fill_color = '#2F2F2F'
    plot_graph.border_fill_color = '#2F2F2F'
    plot_graph.outline_line_color = '#444444'

    return plot_graph
Пример #2
0
def data_visualization(direction):

    Junctions = sites[sites["Direction"] ==direction]["Jct_to_Jct"].unique().tolist()

    TOOLTIPS = [("Hour", "$x{0.0}"),
                    ("Volume", "@y{0,0}"),]
    List1 = []

    March_= March_M25[March_M25["Direction"] ==direction]
    April_= April_M25[April_M25["Direction"]==direction]
    May_= May_M25[May_M25["Direction"]==direction]
    June_= June_M25[June_M25["Direction"]==direction]
    September_= September_M25[September_M25["Direction"]==direction]
    October_= October_M25[October_M25["Direction"]==direction]

    for i in Junctions:
        March1 = March_[March_["Jct_to_Jct"]==i]
        April1 = April_[April_["Jct_to_Jct"]==i]
        May1 = May_[May_["Jct_to_Jct"]==i]
        June1 = June_[June_["Jct_to_Jct"]==i]
        September1 = September_[September_["Jct_to_Jct"]==i]
        October1 = October_[October_["Jct_to_Jct"]==i]

        Ratio = 0
        AADT_List = [March1["Total Volume"].sum(), April1["Total Volume"].sum(), \
                     May1["Total Volume"].sum(), June1["Total Volume"].sum(), \
                September1["Total Volume"].sum(), October1["Total Volume"].sum()]
        AADT_List = [x for x in AADT_List if x!=0]
        AADT = int(np.mean(AADT_List))
        
        HGV_AADT_List = [March1["HGV Volume"].sum(), April1["HGV Volume"].sum(), \
                     May1["HGV Volume"].sum(), June1["HGV Volume"].sum(), \
                September1["HGV Volume"].sum(), October1["HGV Volume"].sum()]
        HGV_AADT_List = [x for x in HGV_AADT_List if x!=0]
        HGV_AADT = int(np.mean(HGV_AADT_List))
       
        try:
            Ratio = round(HGV_AADT/AADT *100, 1)
        except:
            pass

        if "Dartford" in i:
            name = " - " + str(i)
        else:
            name = " - Junction " + str(i[1:])
        
        p = figure(plot_width=950, plot_height=500, \
                 tools=['pan', 'wheel_zoom', 'box_zoom', 'reset', 'save'], \
                   title = str("M25 ") + str(direction) + name + " : " + "AADT = " + "{:,}".format(AADT)  + \
                   " vehicles/day including " + "{:,}".format(HGV_AADT) + " HGV/day (i.e., " + str(Ratio) + "% HGV)." )

        z = p.line(March1["Hour"], March1["Total Volume"], line_width=3, color="purple", alpha=0.5)
        z1 = p.line(March1["Hour"], March1["HGV Volume"], line_width=3, line_dash = 'dashed', color="purple", alpha=0.5)
        
        a = p.line(April1["Hour"], April1["Total Volume"], line_width=3, color="blue", alpha=0.5)
        a1 = p.line(April1["Hour"], April1["HGV Volume"], line_width=3, line_dash = 'dashed', color="blue", alpha=0.5)

        b = p.line(May1["Hour"], May1["Total Volume"], line_width=3, color="green", alpha=0.5)
        b1 = p.line(May1["Hour"], May1["HGV Volume"], line_width=3, line_dash = 'dashed', color="green", alpha=0.5)

        c = p.line(June1["Hour"], June1["Total Volume"], line_width=3, color="red", alpha=0.5)
        c1 = p.line(June1["Hour"], June1["HGV Volume"], line_width=3, line_dash = 'dashed', color="red", alpha=0.5)

        d = p.line(September1["Hour"], September1["Total Volume"], line_width=3, color="orange", alpha=0.5)
        d1 = p.line(September1["Hour"], September1["HGV Volume"], line_width=3, line_dash = 'dashed', color="orange", alpha=0.5)

        e = p.line(October1["Hour"], October1["Total Volume"], line_width=3, color="pink", alpha=0.5)
        e1 = p.line(October1["Hour"], October1["HGV Volume"], line_width=3, line_dash = 'dashed', color="pink", alpha=0.5)

        f = p.line([0,24], [3600,3600], color='brown', line_dash = 'dashed', line_width=1.5)
        g = p.line([0,24], [2400,2400], color='grey', line_dash = 'dashed', line_width=1.5)
        h = p.line([0,24], [1200,1200], color='black', line_dash = 'dashed', line_width=1.5)

        L = [z, z1, a, a1, b, b1, c,c1, d,d1, e,e1, f, g, h]
        L1 = ["March 2019", "HGV March 2019", "April 2019","HGV April 2019", "May 2019", "HGV May 2019","June 2019", "HGV June 2019",\
              "September 2019", "HGV September 2019", "October 2019","HGV October 2019", \
                 "1 Lane Closure Capacity", "2 Lane Closure Capacity",  "3 Lane Closure Capacity"]

        legend_it = []
        for j in range(len(L)):
            legend_it.append((L1[j], [L[j]]))

        p.xaxis.axis_label = 'Hour'
        p.yaxis.axis_label = 'Average of Hourly Flow'
        legend = Legend(items=legend_it, location=(0, 1))
        legend.click_policy="hide"
        legend.title = 'Legend:'
        legend.border_line_color = "black"
        legend.background_fill_color = "white"
        legend.border_line_width = 2
        legend.background_fill_alpha = 1
        legend.title_text_font_style = "bold"
        p.add_layout(legend, 'right')
        p.add_tools(HoverTool(tooltips=TOOLTIPS, line_policy="interp"))
        tab = Panel(child=p, title=i)
        List1.append(tab)

    return List1