Reputation: 1789
I would like to create a bokeh gmap figure with some plotted circles, save that figure's map background, and then create offline figures with new circles on that same map background. For example:
import bokeh.plotting as bk
from bokeh.models import GMapOptions
from bokeh.io import output_file, show, save
output_file('test.html', , mode='inline')
api_key = #insert your key here
mid_lat = 39.8283
mid_lon = 98.5795
map_options = GMapOptions(lat = mid_lat, lng = mid_lon, map_type="satellite", zoom=15)
lons = [mid_lon + 0.001, mid_lon - 0.001, mid_lon]
lats = [mid_lat + 0.001, mid_lat - 0.001, mid_lat]
p = bk.gmap(google_api_key = api_key, map_options = map_options)
p.circle(x = lons, y = lats, color = 'white')
save(p, 'test.html')
show(p)
Gives the following, plotting three white points on the map:
Now, I want to use that same map image off line--with the zoom level, the x and y domains constant. But I want to plot new circles. For example:
lons = [mid_lon + 0.003, mid_lon - 0.003, mid_lon]
lats = [mid_lat + 0.003, mid_lat - 0.003, mid_lat]
Is there a way to save the figure's background image and load it into a new plot? Looking it doesn't look like GMap supports this, but is there a clever workaround to do this in python?
It seems that I might need to save my own tile provider (as shown here), but I think I'm misunderstanding the correct way to do this and then have bokeh re-access the images/tiles offline. But the tiles approach might not even be the way to go for my simple, static map.
Python 3.6, Bokeh 12.7
Upvotes: 2
Views: 1238
Reputation: 34618
If you mean to save e.g. a PNG image of the entire plot, then the standard export functions work with both gmap plots or tile provider plots:
from bokeh.io import export_png
export_png(p, "foo.png")
If you mean you want a standalone HTML file with a real (live) Bokeh plot in it that can display map plots without access to a network, this is not possible. Google map plots always require access to the full internet, and tile provider plots require access to whatever network the tile server is on. There is no way to "embed" map tiles in Bokeh HTML output.
Edit: I suppose you could make a plot with no axes, border, title, etc. and use export_png
to "save the background". You could then need load the PNG and convert it to RGBA numpy array to use with image_rgba
in order to emebd in a standalone Bokeh HTML file. A fair amount of work, and possibly violates Google's TOS.
Upvotes: 1