Python bokeh.models.Plot() Examples

The following are 15 code examples of bokeh.models.Plot(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bokeh.models , or try the search function .
Example #1
Source File: test_annotators.py    From EarthSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_point_annotator_init_models():
    annot = PointAnnotator(point_columns=['Size'], points=sample_points)
    panel = annot.panel()
    root_model = panel.get_root()

    fig = root_model.select_one({'type': Plot})
    points = fig.renderers[-1]
    table = root_model.select_one({'type': DataTable})

    # Ensure points data matches
    for k in sample_points:
        np.testing.assert_allclose(points.data_source.data[k], sample_points[k])

    # Ensure point is linked to table
    point_cbs = points.data_source.js_property_callbacks['change:data']
    assert len(point_cbs) == 1
    assert point_cbs[0].code == PointTableLinkCallback.source_code

    table_cbs = table.source.js_property_callbacks['change:data']
    assert len(table_cbs) == 1
    assert table_cbs[0].code == PointTableLinkCallback.target_code 
Example #2
Source File: test_annotators.py    From EarthSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_point_annotator_updates():
    annot = PointAnnotator(point_columns=['Size'], points=sample_points)
    panel = annot.panel()
    root_model = panel.get_root(comm=Comm()) # Pass comm to ensure update is applied

    updated_points = dict(sample_points, Size=sample_points['Size'][::-1])
    points = Points(updated_points, vdims=['Size'], crs=ccrs.GOOGLE_MERCATOR)
    annot.points = points

    fig = root_model.select_one({'type': Plot})
    points = fig.renderers[-1]
    table = root_model.select_one({'type': DataTable})

    # Ensure points data matches
    for k in updated_points:
        np.testing.assert_allclose(points.data_source.data[k], updated_points[k])

    # Ensure point is linked to table
    point_cbs = points.data_source.js_property_callbacks['change:data']
    assert sum([cb.code == PointTableLinkCallback.source_code
                for cb in point_cbs]) == 1

    table_cbs = table.source.js_property_callbacks['change:data']
    assert len(table_cbs) == 1
    assert table_cbs[0].code == PointTableLinkCallback.target_code 
Example #3
Source File: vtk.py    From panel with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _construct_colorbars(self, color_mappers=None):
        if not color_mappers:
            color_mappers = self.color_mappers
        from bokeh.models import Plot, ColorBar, FixedTicker
        cbs = []
        for color_mapper in color_mappers:
            ticks = np.linspace(color_mapper.low, color_mapper.high, 5)
            cbs.append(ColorBar(
                color_mapper=color_mapper,
                title=color_mapper.name,
                ticker=FixedTicker(ticks=ticks),
                label_standoff=5, background_fill_alpha=0, orientation='horizontal', location=(0, 0)
            ))
        plot = Plot(toolbar_location=None, frame_height=0, sizing_mode='stretch_width',
                    outline_line_width=0)
        [plot.add_layout(cb, 'below') for cb in cbs]
        return plot 
Example #4
Source File: test_annotators.py    From EarthSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_poly_annotator_init_models():
    annot = PolyAnnotator(poly_columns=['Group'], polys=[sample_poly], vertex_columns=['Weight'])
    panel = annot.panel()
    root_model = panel.get_root()

    fig = root_model.select_one({'type': Plot})
    polys = fig.renderers[1]
    table1, table2 = root_model.select({'type': DataTable})
    if 'xs' in table1.source.data:
        table1, table2 = table2, table1 # Ensure tables are correctly ordered

    # Ensure poly data matchs
    np.testing.assert_allclose(polys.data_source.data['xs'][0][:-1], sample_poly['Longitude'])
    np.testing.assert_allclose(polys.data_source.data['ys'][0][:-1], sample_poly['Latitude'])

    # Ensure table and poly data are lnked
    assert table2.source is polys.data_source

    # Ensure poly is linked to vertex table
    poly_cbs = polys.data_source.js_property_callbacks['change:data']
    assert len(poly_cbs) == 1
    assert poly_cbs[0].code == VertexTableLinkCallback.source_code

    table_cbs = table1.source.js_property_callbacks['change:data']
    assert len(table_cbs) == 1
    assert table_cbs[0].code == VertexTableLinkCallback.target_code 
Example #5
Source File: test_annotators.py    From EarthSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_poly_annotator_update_models():
    annot = PolyAnnotator(poly_columns=['Group'], polys=[sample_poly], vertex_columns=['Weight'])
    panel = annot.panel()
    root_model = panel.get_root(comm=Comm()) # Pass comm to ensure update is applied

    poly = Polygons([dict(sample_poly, Test=1)], vdims=['Test'], crs=ccrs.GOOGLE_MERCATOR)
    annot.poly_columns = ['Test']
    annot.polys = poly

    fig = root_model.select_one({'type': Plot})
    polys = fig.renderers[1]
    table1, table2 = root_model.select({'type': DataTable})
    if 'xs' in table1.source.data:
        table1, table2 = table2, table1 # Ensure tables are correctly ordered

    # Ensure poly data matches
    np.testing.assert_allclose(polys.data_source.data['xs'][0][:-1], sample_poly['Longitude'])
    np.testing.assert_allclose(polys.data_source.data['ys'][0][:-1], sample_poly['Latitude'])
    np.testing.assert_allclose(polys.data_source.data['Test'][0], np.ones(6))

    # Ensure table and poly data are linked
    assert table2.source is polys.data_source

    # Ensure poly is linked to vertex table
    poly_cbs = polys.data_source.js_property_callbacks['change:data']
    assert sum([cb.code == VertexTableLinkCallback.source_code
                for cb in poly_cbs]) == 1

    table_cbs = table1.source.js_property_callbacks['change:data']
    assert len(table_cbs) == 1
    assert table_cbs[0].code == VertexTableLinkCallback.target_code 
Example #6
Source File: viz2.py    From scipy2015-blaze-bokeh with MIT License 5 votes vote down vote up
def legend():
    # Set ranges
    xdr = Range1d(0, 100)
    ydr = Range1d(0, 500)
    # Create plot
    plot = Plot(
        x_range=xdr,
        y_range=ydr,
        title="",
        plot_width=100,
        plot_height=500,
        min_border=0,
        toolbar_location=None,
        outline_line_color="#FFFFFF",
    )

    # For each color in your palette, add a Rect glyph to the plot with the appropriate properties
    palette = RdBu11
    width = 40
    for i, color in enumerate(palette):
        rect = Rect(
            x=40, y=(width * (i + 1)),
            width=width, height=40,
            fill_color=color, line_color='black'
        )
        plot.add_glyph(rect)

    # Add text labels and add them to the plot
    minimum = Text(x=50, y=0, text=['-6 ºC'])
    plot.add_glyph(minimum)
    maximum = Text(x=50, y=460, text=['6 ºC'])
    plot.add_glyph(maximum)

    return plot 
Example #7
Source File: viz.py    From scipy2015-blaze-bokeh with MIT License 5 votes vote down vote up
def legend():
    # Set ranges
    xdr = Range1d(0, 100)
    ydr = Range1d(0, 500)
    # Create plot
    plot = Plot(
        x_range=xdr,
        y_range=ydr,
        title="",
        plot_width=100,
        plot_height=500,
        min_border=0,
        toolbar_location=None,
        outline_line_color="#FFFFFF",
    )

    # For each color in your palette, add a Rect glyph to the plot with the appropriate properties
    palette = RdBu11
    width = 40
    for i, color in enumerate(palette):
        rect = Rect(
            x=40, y=(width * (i + 1)),
            width=width, height=40,
            fill_color=color, line_color='black'
        )
        plot.add_glyph(rect)

    # Add text labels and add them to the plot
    minimum = Text(x=50, y=0, text=['-6 ºC'])
    plot.add_glyph(minimum)
    maximum = Text(x=50, y=460, text=['6 ºC'])
    plot.add_glyph(maximum)

    return plot 
Example #8
Source File: viz2.py    From scipy2015-blaze-bokeh with MIT License 5 votes vote down vote up
def legend():
    # Set ranges
    xdr = Range1d(0, 100)
    ydr = Range1d(0, 500)
    # Create plot
    plot = Plot(
        x_range=xdr,
        y_range=ydr,
        title="",
        plot_width=100,
        plot_height=500,
        min_border=0,
        toolbar_location=None,
        outline_line_color="#FFFFFF",
    )

    # For each color in your palette, add a Rect glyph to the plot with the appropriate properties
    palette = RdBu11
    width = 40
    for i, color in enumerate(palette):
        rect = Rect(
            x=40, y=(width * (i + 1)),
            width=width, height=40,
            fill_color=color, line_color='black'
        )
        plot.add_glyph(rect)

    # Add text labels and add them to the plot
    minimum = Text(x=50, y=0, text=['-6 ºC'])
    plot.add_glyph(minimum)
    maximum = Text(x=50, y=460, text=['6 ºC'])
    plot.add_glyph(maximum)

    return plot 
Example #9
Source File: testcallbacks.py    From holoviews with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_server_callback_resolve_attr_spec_tap_event(self):
        plot = Plot()
        event = Tap(plot, x=42)
        msg = Callback.resolve_attr_spec('cb_obj.x', event, plot)
        self.assertEqual(msg, {'id': plot.ref['id'], 'value': 42}) 
Example #10
Source File: testcallbacks.py    From holoviews with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_plotsize_resolves(self):
        points = Points([1, 2, 3])
        PlotSize(source=points)
        plot = bokeh_server_renderer.get_plot(points)
        callback = plot.callbacks[0]
        model = namedtuple('Plot', 'inner_width inner_height ref')(400, 300, {'id': 'Test'})
        width_spec = callback.attributes['width']
        height_spec = callback.attributes['height']
        resolved = callback.resolve_attr_spec(width_spec, model, model=model)
        self.assertEqual(resolved, {'id': 'Test', 'value': 400})
        resolved = callback.resolve_attr_spec(height_spec, model, model=model)
        self.assertEqual(resolved, {'id': 'Test', 'value': 300}) 
Example #11
Source File: visualize_utils.py    From embedding with MIT License 4 votes vote down vote up
def visualize_self_attention_scores(tokens, scores, filename="/notebooks/embedding/self-attention.png",
                                    use_notebook=False):
    mean_prob = np.mean(scores)
    weighted_edges = []
    for idx_1, token_prob_dist_1 in enumerate(scores):
        for idx_2, el in enumerate(token_prob_dist_1):
            if idx_1 == idx_2 or el < mean_prob:
                weighted_edges.append((tokens[idx_1], tokens[idx_2], 0))
            else:
                weighted_edges.append((tokens[idx_1], tokens[idx_2], el))
    max_prob = np.max([el[2] for el in weighted_edges])
    weighted_edges = [(el[0], el[1], (el[2] - mean_prob) / (max_prob - mean_prob)) for el in weighted_edges]

    G = nx.Graph()
    G.add_nodes_from([el for el in tokens])
    G.add_weighted_edges_from(weighted_edges)

    plot = Plot(plot_width=500, plot_height=500,
                x_range=Range1d(-1.1, 1.1), y_range=Range1d(-1.1, 1.1))
    plot.add_tools(HoverTool(tooltips=None), TapTool(), BoxSelectTool())

    graph_renderer = from_networkx(G, nx.circular_layout, scale=1, center=(0, 0))

    graph_renderer.node_renderer.data_source.data['colors'] = Spectral8[:len(tokens)]
    graph_renderer.node_renderer.glyph = Circle(size=15, line_color=None, fill_color="colors")
    graph_renderer.node_renderer.selection_glyph = Circle(size=15, fill_color="colors")
    graph_renderer.node_renderer.hover_glyph = Circle(size=15, fill_color="grey")

    graph_renderer.edge_renderer.data_source.data["line_width"] = [G.get_edge_data(a, b)['weight'] * 3 for a, b in
                                                                   G.edges()]
    graph_renderer.edge_renderer.glyph = MultiLine(line_color="#CCCCCC", line_width={'field': 'line_width'})
    graph_renderer.edge_renderer.selection_glyph = MultiLine(line_color="grey", line_width=5)
    graph_renderer.edge_renderer.hover_glyph = MultiLine(line_color="grey", line_width=5)

    graph_renderer.selection_policy = NodesAndLinkedEdges()
    graph_renderer.inspection_policy = EdgesAndLinkedNodes()

    plot.renderers.append(graph_renderer)

    x, y = zip(*graph_renderer.layout_provider.graph_layout.values())
    data = {'x': list(x), 'y': list(y), 'connectionNames': tokens}
    source = ColumnDataSource(data)
    labels = LabelSet(x='x', y='y', text='connectionNames', source=source, text_align='center')
    plot.renderers.append(labels)
    plot.add_tools(SaveTool())
    if use_notebook:
        output_notebook()
        show(plot)
    else:
        export_png(plot, filename)
        print("save @ " + filename) 
Example #12
Source File: bokeh.py    From histogrammar-python with Apache License 2.0 4 votes vote down vote up
def plot(xLabel='x',yLabel='y',*args):

    from bokeh.models import DataRange1d, Plot, LinearAxis, Grid
    from bokeh.models import PanTool, WheelZoomTool

    xdr = DataRange1d()
    ydr = DataRange1d()

    plot = Plot(x_range=xdr, y_range=ydr, min_border=80)

    extra = list()
    if type(xLabel) is not str and type(yLabel) is not str:
        extra.append(xLabel)
        extra.append(yLabel)
        xLabel = 'x'
        yLabel = 'y'
    elif type(xLabel) is not str: 
        extra.append(xLabel)
        xLabel = 'x'
    elif type(yLabel) is not str:
        extra.append(yLabel)
        yLabel = 'y'
   
    args = extra+list(args) 
    for renderer in args:
         if type(renderer) is not list: 
             plot.renderers.append(renderer)
         else: 
             plot.renderers.extend(renderer)

    #axes
    xaxis = LinearAxis(axis_label=xLabel)
    plot.add_layout(xaxis, 'below')
    yaxis = LinearAxis(axis_label=yLabel)
    plot.add_layout(yaxis, 'left')
    #add grid to the plot 
    #plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
    #plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

    #interactive tools
    plot.add_tools(PanTool(), WheelZoomTool()) #, SaveTool())

    return plot 
Example #13
Source File: showMatLabFig._spatioTemporal.py    From python-urbanPlanning with MIT License 4 votes vote down vote up
def interactiveG(G):
    from bokeh.models.graphs import NodesAndLinkedEdges,from_networkx
    from bokeh.models import Circle, HoverTool, MultiLine,Plot,Range1d,StaticLayoutProvider
    from bokeh.plotting import figure, output_file, show, ColumnDataSource
    from bokeh.io import output_notebook, show
    output_notebook()
    # We could use figure here but don't want all the axes and titles  
    #plot=Plot(plot_width=1600, plot_height=300, tooltips=TOOLTIPS,title="PHmi+landmarks+route+power(10,-5)",x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
    
    output_file("PHMI_network")
    source=ColumnDataSource(data=dict(
        x=locations[0].tolist(),
        #x=[idx for idx in range(len(PHMIList))],
        #y=locations[1].tolist(),
        y=PHMIList,
        #desc=[str(i) for i in PHMIList],
        #PHMI_value=PHMI_dic[0][0].tolist(),    
    ))
    TOOLTIPS=[
        ("index", "$index"),
        ("(x,y)", "($x, $y)"),
        #("desc", "@desc"),
        #("PHMI", "$PHMI_value"),
    ]
    
    
    plot=figure(x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1),plot_width=2200, plot_height=500,tooltips=TOOLTIPS,title="PHMI_network")
    
    #G_position={key:(G.position[key][1],G.position[key][0]) for key in G.position.keys()}
    graph = from_networkx(G,nx.spring_layout,scale=1, center=(0,0))  
    #plot.renderers.append(graph) 
    
    fixed_layout_provider = StaticLayoutProvider(graph_layout=G.position)
    graph.layout_provider = fixed_layout_provider
    plot.renderers.append(graph)
    
    # Blue circles for nodes, and light grey lines for edges  
    graph.node_renderer.glyph = Circle(size=5, fill_color='#2b83ba')  
    graph.edge_renderer.glyph = MultiLine(line_color="#cccccc", line_alpha=0.8, line_width=2)  
      
    # green hover for both nodes and edges  
    graph.node_renderer.hover_glyph = Circle(size=25, fill_color='#abdda4')  
    graph.edge_renderer.hover_glyph = MultiLine(line_color='#abdda4', line_width=4)  
      
    # When we hover over nodes, highlight adjecent edges too  
    graph.inspection_policy = NodesAndLinkedEdges()  
      
    plot.add_tools(HoverTool(tooltips=None))  
     
    colors=('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen')
    ScalePhmi=math.pow(10,1)
    i=0
    for val,idx in zip(phmi_breakPtsNeg, plot_x):
        plot.line(idx,np.array(val)*ScalePhmi,line_color=colors[i])
        i+=1    
        
    show(plot)
    
#06-single landmarks pattern 无人车位置点与对应landmarks栅格图
#convert location and corresponding landmarks to raster data format using numpy.histogram2d 
Example #14
Source File: driverlessCityProject_spatialPointsPattern_association_basic.py    From python-urbanPlanning with MIT License 4 votes vote down vote up
def interactiveG(G):
    from bokeh.models.graphs import NodesAndLinkedEdges,from_networkx
    from bokeh.models import Circle, HoverTool, MultiLine,Plot,Range1d,StaticLayoutProvider
    from bokeh.plotting import figure, output_file, show, ColumnDataSource
    from bokeh.io import output_notebook, show
    output_notebook()
    # We could use figure here but don't want all the axes and titles  
    #plot=Plot(plot_width=1600, plot_height=300, tooltips=TOOLTIPS,title="PHmi+landmarks+route+power(10,-5)",x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
    
    output_file("PHMI_network")
    source=ColumnDataSource(data=dict(
        x=locations[0].tolist(),
        #x=[idx for idx in range(len(PHMIList))],
        #y=locations[1].tolist(),
        y=PHMIList,
        #desc=[str(i) for i in PHMIList],
        #PHMI_value=PHMI_dic[0][0].tolist(),    
    ))
    TOOLTIPS=[
        ("index", "$index"),
        ("(x,y)", "($x, $y)"),
        #("desc", "@desc"),
        #("PHMI", "$PHMI_value"),
    ]
    
    
    plot=figure(x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1),plot_width=2200, plot_height=500,tooltips=TOOLTIPS,title="PHMI_network")
    
    #G_position={key:(G.position[key][1],G.position[key][0]) for key in G.position.keys()}
    graph = from_networkx(G,nx.spring_layout,scale=1, center=(0,0))  
    #plot.renderers.append(graph) 
    
    fixed_layout_provider = StaticLayoutProvider(graph_layout=G.position)
    graph.layout_provider = fixed_layout_provider
    plot.renderers.append(graph)
    
    # Blue circles for nodes, and light grey lines for edges  
    graph.node_renderer.glyph = Circle(size=5, fill_color='#2b83ba')  
    graph.edge_renderer.glyph = MultiLine(line_color="#cccccc", line_alpha=0.8, line_width=2)  
      
    # green hover for both nodes and edges  
    graph.node_renderer.hover_glyph = Circle(size=25, fill_color='#abdda4')  
    graph.edge_renderer.hover_glyph = MultiLine(line_color='#abdda4', line_width=4)  
      
    # When we hover over nodes, highlight adjecent edges too  
    graph.inspection_policy = NodesAndLinkedEdges()  
      
    plot.add_tools(HoverTool(tooltips=None))  
     
    colors=('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen')
    ScalePhmi=math.pow(10,1)
    i=0
    for val,idx in zip(phmi_breakPtsNeg, plot_x):
        plot.line(idx,np.array(val)*ScalePhmi,line_color=colors[i])
        i+=1    
        
    show(plot)
    
#05-single landmarks pattern 无人车位置点与对应landmarks栅格图
#convert location and corresponding landmarks to raster data format using numpy.histogram2d 
Example #15
Source File: driverlessCityProject_spatialPointsPattern_association_basic.py    From python-urbanPlanning with MIT License 4 votes vote down vote up
def interactiveG(G):
    from bokeh.models.graphs import NodesAndLinkedEdges,from_networkx
    from bokeh.models import Circle, HoverTool, MultiLine,Plot,Range1d,StaticLayoutProvider
    from bokeh.plotting import figure, output_file, show, ColumnDataSource
    from bokeh.io import output_notebook, show
    output_notebook()
    # We could use figure here but don't want all the axes and titles  
    #plot=Plot(plot_width=1600, plot_height=300, tooltips=TOOLTIPS,title="PHmi+landmarks+route+power(10,-5)",x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
    
    output_file("PHMI_network")
    source=ColumnDataSource(data=dict(
        x=locations[0].tolist(),
        #x=[idx for idx in range(len(PHMIList))],
        #y=locations[1].tolist(),
        y=PHMIList,
        #desc=[str(i) for i in PHMIList],
        #PHMI_value=PHMI_dic[0][0].tolist(),    
    ))
    TOOLTIPS=[
        ("index", "$index"),
        ("(x,y)", "($x, $y)"),
        #("desc", "@desc"),
        #("PHMI", "$PHMI_value"),
    ]
    
    
    plot=figure(x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1),plot_width=2200, plot_height=500,tooltips=TOOLTIPS,title="PHMI_network")
    
    #G_position={key:(G.position[key][1],G.position[key][0]) for key in G.position.keys()}
    graph = from_networkx(G,nx.spring_layout,scale=1, center=(0,0))  
    #plot.renderers.append(graph) 
    
    fixed_layout_provider = StaticLayoutProvider(graph_layout=G.position)
    graph.layout_provider = fixed_layout_provider
    plot.renderers.append(graph)
    
    # Blue circles for nodes, and light grey lines for edges  
    graph.node_renderer.glyph = Circle(size=5, fill_color='#2b83ba')  
    graph.edge_renderer.glyph = MultiLine(line_color="#cccccc", line_alpha=0.8, line_width=2)  
      
    # green hover for both nodes and edges  
    graph.node_renderer.hover_glyph = Circle(size=25, fill_color='#abdda4')  
    graph.edge_renderer.hover_glyph = MultiLine(line_color='#abdda4', line_width=4)  
      
    # When we hover over nodes, highlight adjecent edges too  
    graph.inspection_policy = NodesAndLinkedEdges()  
      
    plot.add_tools(HoverTool(tooltips=None))  
     
    colors=('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen')
    ScalePhmi=math.pow(10,1)
    i=0
    for val,idx in zip(phmi_breakPtsNeg, plot_x):
        plot.line(idx,np.array(val)*ScalePhmi,line_color=colors[i])
        i+=1    
        
    show(plot)
    
#05-single landmarks pattern 无人车位置点与对应landmarks栅格图
#convert location and corresponding landmarks to raster data format using numpy.histogram2d