Map Background Not Showing

I am attempting to create a map visualization using Bokeh. The points on the map will show up, but the background will not. I am not sure how to address this, and this outcome remains consistent regardless whether I render my visualization in a notebook or website and it does not matter which browser I use. My code is below

from pyproj import Proj, transform
import pandas as pd
import numpy as np
from bokeh.plotting import figure
from bokeh.tile_providers import get_provider, WIKIMEDIA, CARTODBPOSITRON, STAMEN_TERRAIN, STAMEN_TONER, ESRI_IMAGERY, OSM
from bokeh.io import output_notebook, show
import requests
import io
import zipfile
import pandas as pd
from io import StringIO


def download_data(url):
    response = requests.get(url)
    with zipfile.ZipFile(io.BytesIO(response.content)) as thezip:
        for zipinfo in thezip.infolist():
            if 'csv' in str(zipinfo):
                with thezip.open(zipinfo) as thefile:
                    csv_contents = thefile.read().decode('UTF-8')
                    df = pd.read_csv(StringIO(csv_contents))
                    return df
            

def create_df_projections(df):
    inProj = Proj(init='epsg:3857')
    outProj = Proj(init='epsg:4326')

    lons, lats = [], []

    for i in range(0, len(df)):
        lat = df['lat'][i]
        lon = df['lng'][i]
        x, y = transform(outProj,inProj,lon,lat)
        lons.append(x)
        lats.append(y)

    df["MercatorX"] = lons
    df["MercatorY"] = lats
    return df
    
    
def create_map(df):
    inProj = Proj(init='epsg:3857')
    outProj = Proj(init='epsg:4326')

    wikimedia = get_provider(WIKIMEDIA)

    lon1, lat1 = transform(outProj,inProj,-180,-85)
    lon2, lat2 = transform(outProj,inProj,180,85)

    p = figure(plot_width=600, plot_height=600,
               x_range=(lon1, lon2), y_range=(lat1, lat2),
               x_axis_type="mercator", y_axis_type="mercator",
               title="POINTS On Map")

    p.add_tile(wikimedia)

    p.circle(x="MercatorX", y="MercatorY",
             size=2,
             fill_color="dodgerblue", line_color="dodgerblue",
             fill_alpha=0.3,
             source=df)
    return p


url = 'https://simplemaps.com/static/data/world-cities/basic/simplemaps_worldcities_basicv1.74.zip'

df = download_data(url)
df = df.head(250)

df_map = create_df_projections(df)

p = create_map(df_map)
output_notebook()
show(p)

The empty map shows as the image attached. I am using bokeh version 1.4.0

@wtaylorb Wikimedia has restricted the use of their tile server exclusively to sites on Wikimedia domains, i.e. they are not longer publicly available or usable at all. We have no control over this. You will have to choose a different tile provider to use. The WIKIMEDIA option will be removed entirely from Bokeh on the next release.

Just tried using the ESRI tile and it worked fine. Thanks for your timely and helpful response.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.