In [4]:
import json
In [5]:
with open('zones.json') as f:
zones = json.load(f)
In [6]:
from bokeh.io import output_notebook
output_notebook()
In [7]:
zones_xs = []
zones_ys = []
for zone in zones['features']:
zones_xs = zones_xs + [[latlon[0] for latlon in zone['geometry']['coordinates'][0]]]
zones_ys = zones_ys + [[latlon[1] for latlon in zone['geometry']['coordinates'][0]]]
In [8]:
from bokeh.plotting import figure, show, output_file
p = figure(title="Nepal Zones", plot_width=900, plot_height=600)
p.patches(zones_xs, zones_ys, fill_alpha=0.7,
line_color="#884444", line_width=2, line_alpha=0.3)
show(p)
Out[8]:
In [9]:
with open('districts.json') as f:
districts = json.load(f)
In [10]:
districts_xs = []
districts_ys = []
for district in districts['features']:
districts_xs = districts_xs + [[latlon[0] for latlon in district['geometry']['coordinates'][0]]]
districts_ys = districts_ys + [[latlon[1] for latlon in district['geometry']['coordinates'][0]]]
In [11]:
p = figure(title="Nepal Districts", plot_width=900, plot_height=600)
p.patches(districts_xs, districts_ys, fill_alpha=0.7,
line_color="#884444", line_width=2, line_alpha=0.3)
show(p)
Out[11]:
In [15]:
p = figure(title="Nepal Zones and Districts", plot_width=900, plot_height=600)
p.patches(districts_xs, districts_ys, fill_alpha=0.7,
line_color="#eeeeee", line_width=2, line_alpha=0.3)
p.patches(zones_xs, zones_ys, fill_alpha=0.0,
line_color="#884444", line_width=2, line_alpha=0.3)
show(p)
Out[15]:
In [23]:
from bokeh.plotting import ColumnDataSource
from bokeh.models import HoverTool
district_names = [district['properties']['District'] for district in districts['features']]
source = ColumnDataSource(data=dict(
x=districts_xs,
y=districts_ys,
name=district_names,
))
TOOLS="pan,wheel_zoom,box_zoom,reset,hover,save"
p = figure(title="Nepal Districts - Hover them", plot_width=900, plot_height=600, tools=TOOLS)
p.patches('x', 'y', source=source,
fill_alpha=0.7, line_color="#333", fill_color='#999', line_width=1, line_alpha=0.3)
hover = p.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [
("Name", "@name"),
("(Long, Lat)", "($x, $y)"),
]
show(p)