Reputation: 31
The following code, where testdata.json is https://pastebin.com/tCZQGMsK will produce a figure with patches, but when I try to make the exact same patches over a gmap, the patches don't show up.
import geopandas as gpd
import json
from bokeh.models import GeoJSONDataSource, GMapOptions, LinearColorMapper
from bokeh.io import output_notebook, show, output_file
from bokeh.plotting import gmap, figure
file = gpd.read_file("testdata.json")
j = json.loads(file.to_json())
data = json.dumps(j)
data_source = GeoJSONDataSource(geojson = data)
output_notebook()
map_options = GMapOptions(lat=30.2861, lng=-97.7394, map_type="roadmap", zoom=11)
#this produces a figure
fig = figure()
fig.patches('xs','ys', source = data_source,
line_color = 'black', line_width = 0.25, fill_alpha = 1)
#there are no patches on this
plot = gmap("i keep posting this with my api key...", map_options, title = "test", tools="hover")
plot.patches('xs','ys', source = data_source,
line_color = 'black', line_width = 0.25, fill_alpha = 1)
show(plot)
output_file("gmap.html")
Upvotes: 1
Views: 358
Reputation: 10727
It works just fine for me - make sure that your coordinates and your color mapper are correct. Check also if there are any errors in the JavaScript console or Python output.
Regarding the plot object not having a patches function - that's because you're using a plot model explicitly as opposed to using a higher level API. See the example below.
from bokeh.io import show
from bokeh.models import ColumnDataSource, GMapOptions
from bokeh.plotting import gmap
map_options = GMapOptions(lat=30.2861, lng=-97.7394, map_type="roadmap", zoom=11)
p = gmap(%YOUR_API_KEY%, map_options, title="Austin")
source = ColumnDataSource(data=dict(lats=[[30.29, 30.20, 30.29]],
lons=[[-97.70, -97.74, -97.78]]))
p.patches(xs="lons", ys="lats", fill_alpha=0.8, source=source)
show(p)
You don't need geopandas
and json
, just read the file as is and pass it to the data source:
with open("testdata.json") as file:
data_source = GeoJSONDataSource(geojson=file.read())
But the more important thing is that you have bad data. Check out the coordinates in your JSON. It has numbers like 3538864.641298605
, which is clearly neither latitude nor longitude. And that's exactly why you don't see anything on GMap.
Upvotes: 1