Hello,
I was playing around with the geographic plots (of the tutorials section, chapter 9) but I may not understand how it works. Indeed, I tried, just for the fun of learning, to add labels using the LabelSet class from section 4. But it doesn’t work.
Can someone help me to understand that please? Thanks!
Sébastien.
import pandas as pd
import numpy as np
from bokeh.models import LabelSet
def wgs84_to_web_mercator(df, lon="lon", lat="lat"):`
"""Converts decimal longitude/latitude to Web Mercator format"""
k = 6378137
df["x"] = df[lon] * (k * np.pi/180.0)
df["y"] = np.log(np.tan((90 + df[lat]) * np.pi/360.0)) * k
return df
df = pd.DataFrame(dict(names=["Austin", "NYC", "Btown", "Escalante"], lon=[-97.7431,-74.0059,-86.529167,-111.602222], lat=[30.2672,40.7128,39.162222,37.770278]))
wgs84_to_web_mercator(df)
p = figure(tools='pan, wheel_zoom', x_range=x_range, y_range=y_range,
x_axis_type="mercator", y_axis_type="mercator")
p.add_tile(WMTSTileSource(url=url, attribution=attribution))
p.circle(x=df['x'], y=df['y'], fill_color='orange', size=10)
labels = LabelSet(x=df['x'], y=df['y'], text=df['names'], level='glyph',
x_offset=5, y_offset=5, source=df, render_mode='canvas')
p.add_layout(labels)
show(p)