bokeh / bokeh

Interactive Data Visualization in the browser, from Python
https://bokeh.org
BSD 3-Clause "New" or "Revised" License
19.23k stars 4.18k forks source link

Gmaps incompatible with DataRange1d, make error louder/earlier #7028

Closed mhamilton723 closed 6 years ago

mhamilton723 commented 6 years ago

Runtime Info:

notebook server is 5.0.0 Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:09:58) IPython 6.0.0 bokeh '0.12.9' ipywidgets '7.0.1' ubuntu 16

When i run the gmaps demo with push notebook it displays the dots in the wrong location until i interact with he map.

from bokeh.io import output_file, show
from bokeh.models import (
  GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d, PanTool, WheelZoomTool, BoxSelectTool
)

map_options = GMapOptions(lat=30.29, lng=-97.73, map_type="roadmap", zoom=11)

plot = GMapPlot(
    x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options
)
plot.title.text = "Austin"

plot.api_key = API_KEY

source = ColumnDataSource(
    data=dict(
        lat=[],
        lon=[],
    )
)

circle = Circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.8, line_color=None)
plot.add_glyph(source, circle)

plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
h = show(plot, notebook_handle=True)
source.data = dict(
        lat=[30.29, 30.20, 30.29],
        lon=[-97.70, -97.74, -97.78],
    )
push_notebook(handle=h)

pre interaction image

post interaction image

bryevdv commented 6 years ago

DataRange1d is incompatible with GmapPlot, which must defer to the google maps API to set ranges. Use Range1d instead. I’ll leave this issue as a task to make it fail earlier and louder.

mhamilton723 commented 6 years ago

Thanks for the quick reply, this was exactly what was needed! You might want to also mark this as a task to change the documentation as well.

bryevdv commented 6 years ago

@mhamilton723 is it demonstrated incorrectly with a DataRange1d some place? If so a specific pointer to a location would help. If not, I'll probably leave it:

bryevdv commented 6 years ago

@mattpap I think the proper way to do this will mean factoring much of Plot into a BasePlot that both Plot and MapPlot can separately inherit from. Then GMapPlot can define more restrictive range properties.

mattpap commented 6 years ago

I'm not sure if such deep changes are really needed for this purpose. An error message can be achieved by cheaper means. If however want to proceed, then I would leave this for the next release, so at least I have some time to give this a thought.

bryevdv commented 6 years ago

The only other way to catch it in all cases is a validation error, which also does not seem ideal.

bryevdv commented 6 years ago

This started getting pretty hairy, I think I will just add a check at __init__ as well as a validation error after all.