def plot_data(data_df, connections, year, geoSource_new): data_df_countries = data_df #.drop_duplicates(subset=None, keep='first', inplace=True) connections_df = connections node_source = ColumnDataSource( data_df_countries[["country_id", "Country", "Longitude", "Latitude"]]) edge_source = ColumnDataSource(connections_df[["start", "end"]]) node_renderer = GlyphRenderer(data_source=node_source, glyph=node_glyph, selection_glyph=node_selection, nonselection_glyph=node_nonselection) ## Create edge_renderer edge_renderer = GlyphRenderer(data_source=edge_source, glyph=edge_glyph, hover_glyph=edge_hover, selection_glyph=edge_selection, nonselection_glyph=edge_nonselection) ## Create layout_provider graph_layout = dict( zip(data_df_countries.country_id.astype(str), zip(data_df_countries.Longitude, data_df_countries.Latitude))) layout_provider = StaticLayoutProvider(graph_layout=graph_layout) ## Create graph renderer graph = GraphRenderer(edge_renderer=edge_renderer, node_renderer=node_renderer, layout_provider=layout_provider, inspection_policy=NodesAndLinkedEdges(), selection_policy=NodesAndLinkedEdges()) plot = Plot(x_range=Range1d(-150, 150), y_range=Range1d(15, 75), plot_width=800, plot_height=600, background_fill_color=Set3_12[4], background_fill_alpha=0.2) plot.title.text = "Human Trafficing Visualization for " + str(year) # plot.add_glyph( geoSource_data, Patches(xs='xs', ys='ys', line_color='grey' # , line_width=.5, fill_color=Set3_12[6], fill_alpha=0.25)) plot.add_glyph( geoSource_new, Patches(xs='xs', ys='ys', line_color='grey', line_width=.2, fill_color={ 'field': 'Tier', 'transform': mapper2 }, fill_alpha=0.25)) plot.renderers.append(graph) plot.add_layout(LinearAxis(axis_label="Latitude"), "below") plot.add_layout(LinearAxis(axis_label="Longitude"), "left") hover = HoverTool( show_arrow=True, # tooltips= # [("Country Involved: ", "@Country")], tooltips=""" <div> <div> <span style="font-size: 15px;">Country Information </span> <span style="font-size: 12px; color: #696;">@Destination_Country </span> </div> </div> """, renderers=[graph]) hover_no_tooltips = HoverTool(tooltips=None, renderers=[graph]) box_zoom = BoxZoomTool() plot.add_tools(hover, hover_no_tooltips, box_zoom, TapTool(), BoxSelectTool(), ResetTool(), WheelZoomTool()) plot.toolbar.active_inspect = [hover, hover_no_tooltips] plot.toolbar.active_drag = box_zoom plot.outline_line_color = "navy" plot.outline_line_alpha = 0.3 plot.outline_line_width = 3 plot.add_tile(STAMEN_TONER_LABELS) return plot
def plot_data(data_df, connections, year, geoSource_new, df): d_yr = df[df['Years'] == year] data_df_countries = d_yr.merge(data_df, left_on='Origin_Country', right_on='Country') #data_df_countries = node_dt #.drop_duplicates(subset=None, keep='first', inplace=True) connections_df = connections # node_source = ColumnDataSource(data_df_countries[["country_id","Country", "Longitude", "Latitude"]]) node_source = ColumnDataSource(data_df_countries) edge_source = ColumnDataSource(connections_df[["start", "end"]]) node_renderer = GlyphRenderer(data_source=node_source, glyph=node_glyph, selection_glyph=node_selection, nonselection_glyph=node_nonselection) ## Create edge_renderer edge_renderer = GlyphRenderer(data_source=edge_source, glyph=edge_glyph, hover_glyph=edge_hover, selection_glyph=edge_selection, nonselection_glyph=edge_nonselection) ## Create layout_provider graph_layout = dict( zip(data_df_countries.country_id.astype(str), zip(data_df_countries.Longitude, data_df_countries.Latitude))) layout_provider = StaticLayoutProvider(graph_layout=graph_layout) ## Create graph renderer graph = GraphRenderer(edge_renderer=edge_renderer, node_renderer=node_renderer, layout_provider=layout_provider, inspection_policy=NodesAndLinkedEdges(), selection_policy=NodesAndLinkedEdges()) plot = Plot(x_range=Range1d(-150, 150), y_range=Range1d(15, 75), plot_width=800, plot_height=600, background_fill_color=Set3_12[4], background_fill_alpha=0.2) plot.title.text = "Human Trafficing Visualization for " + str(year) plot.add_glyph( geoSource_new, Patches(xs='xs', ys='ys', line_color='grey', line_width=.2, fill_color={ 'field': 'Tier', 'transform': mapper2 }, fill_alpha=0.40)) plot.renderers.append(graph) plot.add_layout(LinearAxis(axis_label="Latitude"), "below") plot.add_layout(LinearAxis(axis_label="Longitude"), "left") # tooltips=""" # <div> # <div> # <span style="font-size: 17px; font-weight: bold;">@desc</span> # <span style="font-size: 15px; color: #966;">[$index]</span> # </div> # <div> # <span style="font-size: 15px;">Country Involved</span> # <span style="font-size: 10px; color: #696;">@Country</span> # </div> # </div> # """, hover = HoverTool( show_arrow=True, # tooltips= # [("Country Involved: ", "@Country")], tooltips=""" <div> <div> <span style="font-size: 13px;">Country Info</span> <span style="font-size: 12px; color: #696;">@Destination_Country, @Type_Of_Trafficking</span> </div> </div> """, renderers=[node_renderer], name='Test') hover_no_tooltips = HoverTool(tooltips=None, renderers=[graph]) box_zoom = BoxZoomTool() plot.add_tools(hover, hover_no_tooltips, box_zoom, TapTool(), BoxSelectTool(), ResetTool(), WheelZoomTool()) plot.toolbar.active_inspect = [hover, hover_no_tooltips] plot.toolbar.active_drag = box_zoom plot.outline_line_color = "navy" plot.outline_line_alpha = 0.3 plot.outline_line_width = 1 select_overlay = plot.select_one(BoxSelectTool).overlay select_overlay.fill_color = "firebrick" select_overlay.line_color = None zoom_overlay = plot.select_one(BoxZoomTool).overlay zoom_overlay.line_color = "olive" zoom_overlay.line_width = 3 zoom_overlay.line_dash = "solid" zoom_overlay.fill_color = None plot.add_tile(STAMEN_TONER_LABELS) return plot