Created
March 11, 2020 18:45
-
-
Save janpipek/130b29cd2afb641edd415f60fb3f72c3 to your computer and use it in GitHub Desktop.
Plot simple map with Prague and
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bokeh.plotting import figure, show, output_notebook | |
from bokeh.models import HoverTool | |
from bokeh.tile_providers import Vendors, get_provider | |
import pandas as pd | |
def web_mercator(long, lat): | |
import numpy as np | |
scale_x = 4e7 / 360 | |
limit_lat = 2 * np.arctan(np.exp(np.pi)) - np.pi / 2 | |
scale_y = 2e7 / np.log(np.tan(np.pi / 4 + limit_lat / 2)) | |
x = scale_x * long | |
lat_rad = np.pi / 180 * lat | |
y = scale_y * (np.log(np.tan(np.pi / 4 + lat_rad / 2)) ) | |
return x, y | |
data = pd.DataFrame( | |
[ | |
("Prague", 50, 14.5, 50), | |
("Wuhan", 30.5, 114.25, 50000) | |
], columns=["name", "lat", "long", "cases"] | |
) | |
web_mercator_coords = web_mercator(data["long"], data["lat"]) | |
data = data.assign( | |
wx=web_mercator_coords[0], | |
wy=web_mercator_coords[1], | |
radius = np.log(data["cases"]) * 100000 | |
) | |
output_notebook() | |
tile_provider = get_provider(Vendors.CARTODBPOSITRON) | |
tools = 'hover,box_zoom,pan,save,reset,wheel_zoom' | |
p = figure(x_range=(-18000000, 18000000), y_range=(-4000000, 7000000), | |
x_axis_type="linear", y_axis_type="linear", tools=tools) | |
p.add_tile(tile_provider) | |
p.circle(x="wx", y="wy", radius="radius", alpha=0.5, source=data) | |
hover = p.select(dict(type=HoverTool)) | |
hover.tooltips = [("Place", "@name"), ("Cases", "@cases"),] | |
hover.mode = 'mouse' | |
show(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment