Reputation: 1112
I am following https://towardsdatascience.com/exploring-and-visualizing-chicago-transit-data-using-pandas-and-bokeh-part-ii-intro-to-bokeh-5dca6c5ced10 example to plot some dots on a tile using longitude and latitude. Here is my code.
from bokeh.plotting import figure, show, output_notebook
from bokeh.tile_providers import CARTODBPOSITRON
p = figure(x_axis_type="mercator", y_axis_type="mercator")
p.add_tile(CARTODBPOSITRON)
p.circle(x = us['Evt_Latitude__c'],
y = us['Evt_Longitude__c'])
output_notebook()
show(p)
Despite following the code step by step , my dots are not plotted on the US tile, but on a gray tile with no state name, demarcation, etc. etc. See attached, yet you can see the US shape and realize the geolocation actually worked
What did I get wrong?
Upvotes: 2
Views: 897
Reputation: 100
try to use those lines instead :
from bokeh.tile_providers import get_provider, Vendors
tile_provider = get_provider(Vendors.CARTODBPOSITRON)
p.add_tile(tile_provider)
if this isn't working see if your Web Mercator format fits.
this is a converter from decimal to mercator
def wgs84_to_web_mercator(df, lon="x", lat="y"):
"""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
hope it'll help.
Upvotes: 2