示例#1
0
    NodesAndLinkedEdges,
    StaticLayoutProvider,
    TapTool,
)
from bokeh.palettes import Set3_12
from bokeh.plotting import figure, output_file, show
from bokeh.sampledata.airport_routes import airports, routes
from bokeh.sampledata.us_states import data as us_states

output_file("graphs.html")

airports.set_index("AirportID", inplace=True)
airports.index.rename("index", inplace=True)
routes.rename(columns={
    "SourceID": "start",
    "DestinationID": "end"
},
              inplace=True)

lats, lons = [], []
for k, v in us_states.items():
    lats.append(np.array(v['lats']))
    lons.append(np.array(v['lons']))

source = ColumnDataSource(data=dict(lats=lats, lons=lons))

graph_layout = dict(
    zip(airports.index.astype(str), zip(airports.Longitude,
                                        airports.Latitude)))
layout_provider = StaticLayoutProvider(graph_layout=graph_layout)
示例#2
0
from bokeh.models import StaticLayoutProvider, ColumnDataSource, HoverTool, TapTool
from bokeh.models.graphs import NodesAndLinkedEdges
from bokeh.palettes import Set3_12
from bokeh.plotting import figure, show, output_file
from bokeh.sampledata.us_states import data as us_states
from bokeh.sampledata.airport_routes import airports, routes

import numpy as np

output_file("graphs.html")

airports.set_index("AirportID", inplace=True)
airports.index.rename("index", inplace=True)
routes.rename(columns={"SourceID": "start", "DestinationID": "end"}, inplace=True)

lats, lons = [], []
for k, v in us_states.items():
    lats.append(np.array(v['lats']))
    lons.append(np.array(v['lons']))

source = ColumnDataSource(data=dict(lats=lats, lons=lons))

graph_layout = dict(zip(airports.index.astype(str), zip(airports.Longitude, airports.Latitude)))
layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

fig = figure(x_range=(-180, -60), y_range=(15,75),
              x_axis_label="Longitude", y_axis_label="Latitude",
              plot_width=800, plot_height=600, background_fill_color=Set3_12[4],
              background_fill_alpha=0.2, tools='box_zoom,reset')

fig.patches(xs="lons", ys="lats", line_color='grey', line_width=1.0,